2016-01-02 109 views
6

當我運行的WebPack,我得到這個錯誤:(新行增加了清晰度)的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)/} 
     ] 
    } 
}; 

我不知道如何進一步調查該問題。

回答

3

當我跑了玩笑,一切根據開玩笑的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 
} 
7

的的WebPack entry選項通常決定於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.

+0

奇怪的是,當我在我的webpack配置中設置了'resolve.root'時,它與我上面的入口點一起工作。 – bigblind

+0

或者您可以設置resolve.root - 在這種情況下不需要'/','./'或'../' –

+0

這是幫助我的答案! –

0

您需要的WebPack告訴加載模塊(您game.js)無論從__dirname或您定義的任何路徑。隨着的WebPack 2,有兩種選擇:

解決方案1: 一下添加到webpack.config.js resolve: { modules: [__dirname, 'node_modules'] } 解決方案2: 前綴你game.js./或類似__dirname + '/game.js'