基本上,我正在设置webpack,当我尝试在webpack中以开发模式获取dev-server时,遇到了此错误。
我尝试按照其他说明进行操作,从头开始尝试了两次,但仍然遇到相同的错误。我无法弄清楚我在做什么错。如果有人对此问题有解决方案,我将非常感谢。谢谢。
我遇到的错误:
bundle.js:20 Uncaught TypeError: Cannot read property 'call' of undefined
at __webpack_require__ (bundle.js:20)
at eval (index.js:2)
at Object../src/js/index.js (bundle.js:357)
at __webpack_require__ (bundle.js:20)
at eval (webpack:///multi_(:8080/webpack)-dev-server/client?:2:18)
at Object.0 (bundle.js:368)
at __webpack_require__ (bundle.js:20)
at bundle.js:69
at bundle.js:72
错误说明:
// Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
webpack.config.js:
const path = require('path');
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/bundle.js'
},
devServer: {
contentBase: './dist'
}
};
package.json:
{
"name": "forkify",
"version": "1.0.0",
"description": "forkify project",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "Jonas Schmedtmann",
"license": "ISC",
"devDependencies": {
"webpack": "^4.2.0"
},
"dependencies": {
"webpack-cli": "^2.1.5",
"webpack-dev-server": "^3.4.1"
}
}
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="js/bundle.js"></script>
</body>
</html>
我希望对此有解决方案。
答案 0 :(得分:0)
昨天我遇到了同样的问题,并且在网上进行了很多讨论。很少有人认为这是由于webpack-dev-server中的错误引起的,很少有人认为这是由于不正确的块导入引起的。但是,当我生成单个块文件时,情况并非如此。 对我有用的是完全删除node_modules文件夹并重新进行 npm安装。祝你好运。