我已经根据按钮点击动态导入了我的一些模块,我使用了如下所示
import { Button } from '@syncfusion/ej2-buttons';
// Initialize Button component.
let button: Button = new Button({ content: 'Button' });
// Render initialized Button.
button.appendTo('#element');
document.getElementById('element').addEventListener("click", function(){
check();
});
async function check() {
import("@syncfusion/ej2-grids").then((Grid) => {
debugger
console.log(Grid);
});
}
我的webpack配置文件:
const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
mode: "development",
entry: {
"src/app/bundle": "./src/app/index.ts"
},
output: {
publicPath: "/js/",
filename: "src/app/bundle.js"
},
devtool: "none",
module: {
rules: [
{
loader: "ts-loader",
exclude: /node_modules/
}
]
},
resolve: {
extensions: [".ts", ".js"]
}
};
当我编译和运行我的应用程序时,它会抛出错误下面。
当前的行为是什么?
抛出以下错误

如果当前行为是错误,请提供复制步骤。
clone sample - https://github.com/kumaresan-subramani/dynamic-import/blob/master/webpack.config.js
run npm i
gulp compile
gulp start然后单击浏览器中的按钮,您将在我的控制台中看到报告的错误。
预期的行为是什么?
动态模块应正确加载
其他相关信息:
"typescript": "3.7.5",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack": "^4.29.6",
"webpack-cli": "*",
"webpack-stream": "^5.2.1"
Node.js version: 10.15.1
Operating System: windows 10发布于 2020-02-07 16:44:33
整个逻辑对我来说似乎很奇怪。如果您使用一个模块,只需导入它,然后在特定条件下或在触发事件之后使用它。
https://stackoverflow.com/questions/60056219
复制相似问题