Webpack 找不到网页包输入模块
运行webpack时,出现以下错误:Webpack 找不到网页包输入模块,webpack,babeljs,Webpack,Babeljs,运行webpack时,出现以下错误: ERROR in Entry module not found: Error: Cannot resolve module 'game' in /Users/frederikcreemers/dev/dark_chess (为清晰起见,添加了换行符。) 但我确信game.js是存在的 下面是我的webpack.config.js的样子: module.exports = { entry: "game.js", output: {
ERROR in Entry module not found: Error: Cannot resolve module 'game'
in /Users/frederikcreemers/dev/dark_chess
(为清晰起见,添加了换行符。)
但我确信game.js
是存在的
下面是我的webpack.config.js
的样子:
module.exports = {
entry: "game.js",
output: {
path: __dirname + "build",
filename: "index.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" },
{ test: /\.jsx?$/, loader: "babel?presets[]=es2015", exclude: /(node_modules|bower_components)/}
]
}
};
我不知道如何进一步调查这个问题。当我运行jest时,根据jest网页教程设置了所有内容,我收到了以下消息:
Using Jest CLI v0.8.2, jasmine1
FAIL __tests__/test_game.js
● Runtime Error
Error: Missing setting "resolve.root" in /Users/frederikcreemers/dev/dark_chess/webpack.config.js
因此,我了解到问题在于缺少配置值。将此添加到我的webpack.config.js
解决了我的问题:
"resolve": {
"root": __dirname
}
webpack选项通常解析为一个
因此,您可能需要指出game.js
文件模块的相对路径:
entry: "./game.js",
否则,webpack将尝试将其作为核心模块或从node\u modules
文件夹加载
如果没有前导“/”、“./”或“../”来指示文件,则模块
必须是核心模块或从节点\模块文件夹加载
您需要告诉webpack从
\uuu dirname
或您定义的任何路径加载模块(您game.js
)。对于webpack 2,有两个选项:
解决方案1:
将此添加到webpack.config.js
:
决心:{
模块:[[uuuu dirname,'node\u modules']
}
解决方案2:
在你的
game.js
前面加上/
或类似\uuu dirname+'/game.js'
的前缀。奇怪的是,当我在我的网页配置中设置了resolve.root
时,它可以与我上面的入口点一起工作。或者你可以设置resolve.root-不需要“/”、“/”或“../”在那种情况下,这就是帮助我的答案!