webpack: Webpack doesn't seem to find module when absolute context path is not based off current directory

My folder structure looks like this:

project
    app
        public
            entry.coffee
    build
        webpack.config.js
    dist
    test

My webpack.config.js looks like this:

module.exports = {
    cache: true,
    context: path.resolve(__dirname + "/../app/public"),
    entry: "./entry.coffee",
...

I’m receiving this error:

ERROR in Entry module not found: Error: Cannot resolve file or directory ./entry.coffee in /usr/local/webprojects/webpack/app/public

but the file ‘/usr/local/webprojects/webpack/app/public/entry.coffee’ does exist.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 28 (6 by maintainers)

Most upvoted comments

Run it with --display-error-details and it says why it cannot resolve it.

No and probably never was. Close it.

@lancekuttner you could have used resolve in webpack.config.js to allow .jsx extensions:


  resolve: {
    extensions: [".jsx", ".json", ".js"]
  },

This error may be caused by a syntax error in package.json.

For me this happened because in my entry object I wrote:

app: path.resolve(__dirname, '/test.js'),

While I should have written one of these:

app: path.join(__dirname, '/test.js'),
app: path.join(__dirname, 'test.js'),
app: path.resolve(__dirname, 'test.js'),

The problem was that path.resolve will ignore any parameters given to it before the last parameter that starts with a /.

So path.resolve(__dirname, '/test.js'), will return /test.js instead of /path/of/your/project/directory/test.js.

What is the problem in this webpack entry?

image

I just ran into this using the CLI.

$ webpack index.js

is valid, but

$ webpack index=index.js anotherPage=anotherPage.js

fails with this error. The solution is to specify the full relative path:

$ webpack index=./index.js anotherPage=./anotherPage.js

could also happen if you haven’t installed babel-loader

This happened to me, and this issue was that had the following:

    entry: {
	'app/public/bundle.js': 'app/index.js',
	'app/server.js': 'app/server.js'
    },

    output: {
	path: path.resolve (__dirname, 'dist'),
	filename: '[name]'
    },

… instead of:

    entry: {
	'app/public/bundle.js': './app/index.js',
	'app/server.js': './app/server.js'
    },
    output: {
	path: path.resolve (__dirname, 'dist'),
	filename: '[name]'
    }

See if you can even find the difference (and once you do, see if it should even matter… relative paths should be considered to be rooted at whatever “./” is by whatever is interpreting the relative path… no?)

I had to ensure that I displayed the full extension e.g. ‘./MyComponent.jsx’ instead of ‘./MyComponent’

@towry is the best in the world forgot a comma in .json

My json is fine linted ok. I have the following structure ROOT/src/entry.js

ROOT:webpack.config.js module.exports = { entry: ‘./src’, output: { path: ‘build’, filename: ‘bundle.js’, }, };

I tried …/src /src and src so I am a bit at a loss…anyone any ideas ? TY

[SOLVED FOR ME] I need to actually state the entry

entry: ‘./src/entry.js’,

Thanks. Mine was. Turns out I was using webpack build instead of just webpack as my command, which strangely gave me the same error and led me here…

package.json needs to be in valid JSON syntax On Sep 17, 2015 10:32, “Ameen Soleimani” notifications@github.com wrote:

@saschagehlich https://github.com/saschagehlich @towry https://github.com/towry could either of you elaborate? I’m running into the same issue and I can’t figure out what’s causing it.

— Reply to this email directly or view it on GitHub https://github.com/webpack/webpack/issues/223#issuecomment-141005095.