[英]Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition
I'm receiving this error:我收到此错误:
Uncaught TypeError: Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition (esprima.js:11) at esprima.js:12
未捕获的类型错误:无法在 esprima.js:12 的 webpackUniversalModuleDefinition (esprima.js:11) 处设置未定义的属性“esprima”
When trying to load a web app:尝试加载 web 应用程序时:
The error happens here:错误发生在这里:
(function webpackUniversalModuleDefinition(root, factory) {
/* istanbul ignore next */
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
/* istanbul ignore next */
else if(typeof exports === 'object')
exports["esprima"] = factory();
else
root["esprima"] = factory(); // ** => error is thrown here
})(this, function() {
// ...
});
For reference, the file webpack.config.js
is:作为参考,文件
webpack.config.js
是:
// webpack.config.js
module.exports = {
entry: {
// import: './src/Three.js'
},
mode: 'production',
output: {
path: __dirname,
publicPath: '/',
filename: './build/three.min.js'
},
devServer: {
watchContentBase: true,
publicPath: "/",
contentBase: "./",
hot: true,
port: 9090,
},
};
Can anyone provide a clue what might be wrong?谁能提供线索可能出了什么问题?
The error is resolved by using WebPack script-loader
which loads as simple script rather than module:该错误通过使用 WebPack
script-loader
解决,该脚本加载器作为简单脚本而不是模块加载:
https://v4.webpack.js.org/loaders/script-loader/ https://v4.webpack.js.org/loaders/script-loader/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.