找不到 webpack 入口模块

webpack entry module not found

当我 运行 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: {
        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 webpack 教程设置了所有内容,我收到了这条消息:

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 entry option usually resolves to a File Module.

因此,您可能需要指出 game.js 文件模块的相对路径:

entry: "./game.js",

否则 webpack 将尝试将其作为核心模块或从 node_modules 文件夹加载。

Without a leading '/', './', or '../' to indicate a file, the module must either be a core module or is loaded from a node_modules folder.

您需要告诉 webpack 从 __dirname 或您定义的任何路径加载模块(您 game.js)。对于 webpack 2,有两个选项:

解决方案一: 将此添加到 webpack.config.js resolve: { modules: [__dirname, 'node_modules'] } 解决方案 2: 在 game.js 前加上 ./ 或类似 __dirname + '/game.js'.

的前缀