Webpack input module not found

When I start webpack, I get this error:

ERROR in Entry module not found: Error: Cannot resolve module 'game' in /Users/frederikcreemers/dev/dark_chess 

(A new line has been added for clarity.)

But I'm sure game.js exists.

Here is what my webpack.config.js looks like:

 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)/} ] } }; 

I am not sure how to continue investigating the problem.

+6
source share
3 answers

When I ran the joke, with everything that was configured in accordance with the just webpack training course, I received this message:

 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 

So, I found out that the problem is the lack of a configuration value. Adding this to my webpack.config.js solved the problem for me:

  "resolve": { "root": __dirname } 
+3
source

The webpack entry parameter usually enables the File Module .

So, probably, you need to specify the relative path to the game.js file module:

 entry: "./game.js", 

Otherwise, webpack will try to load it as the main module or from the node_modules folder.

Without the "/", "./", or "../" instructions, to indicate a file, the module must be either the main module or loaded from the node_modules folder.

+7
source

You need to tell webpack to load the modules (you are game.js ) from __dirname or any path you define. There are two options with webpack 2:

Solution 1: Add this to webpack.config.js : resolve: { modules: [__dirname, 'node_modules'] } Solution 2: Prefix game.js with ./ or something like __dirname + '/game.js' .

0
source

All Articles