webpack: Module not found - webpack looking for filename prefixed with backslash

I’m new to webpack, so if I’m missing something obvious help would be much appreciated, but I’ve been experiencing issues with finding modules.

For background, I’m attempting to move our project over from AMD/RequireJS, so most of our require paths are relative to the project root instead of relative to the file. The project root is ./web/coffee/editor (relative to the repo root), and so a file might require('analytics') to require ./web/coffee/editor/analytics.coffee.

I figured I’d set the resolve.root:

module.exports = {
    entry: './web/coffee/editor/main',
    output: {
        path: './web/static/build',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            { test: /\.coffee$/, loader: 'coffee-loader' },
            // { test: /\.css$/, loader: 'style!css' }
        ]
    },
    resolve: {
        alias: {
            'raven$': '../../static/lib/raven.jquery.native.min.js'
        },
        extensions: ['', '.js', '.json', '.coffee'],
        root: './web/coffee/editor'
    },
    bail: true
};

However, from the errors I get it looks like webpack is attemping to load ./web/coffee/editor\analytics.coffee (note the backslash) instead of ./web/coffee/editor/analytics.coffee (which exists!)

ModuleNotFoundError: Module not found: Error: Cannot resolve module 'analytics' in /Users/joshma/myproject/web/coffee/editor
  at Tapable.<anonymous> (/usr/local/lib/node_modules/webpack/lib/Compilation.js:213:38)
  at Tapable.<anonymous> (/usr/local/lib/node_modules/webpack/lib/NormalModuleFactory.js:55:19)
  ...truncated...

resolve module analytics in /Users/joshma/myproject/web/coffee/editor
  looking for modules in ./web/coffee/editor
    ./web/coffee/editor\analytics doesn't exist (module as directory)
    resolve 'file' analytics in ./web/coffee/editor
      resolve file
        ./web/coffee/editor\analytics doesn't exist
        ./web/coffee/editor\analytics.js doesn't exist
        ./web/coffee/editor\analytics.json doesn't exist
        ./web/coffee/editor\analytics.coffee doesn't exist
  looking for modules in /Users/joshma/myproject/node_modules
    /Users/joshma/myproject/node_modules/analytics doesn't exist (module as directory)
    resolve 'file' analytics in /Users/joshma/myproject/node_modules
      resolve file
        /Users/joshma/myproject/node_modules/analytics doesn't exist
        /Users/joshma/myproject/node_modules/analytics.js doesn't exist
        /Users/joshma/myproject/node_modules/analytics.json doesn't exist
        /Users/joshma/myproject/node_modules/analytics.coffee doesn't exist

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Will do. Definitely yes, it is realistic, but put yourself in the position of a newbie who knows absolutely nothing about webpack, little about node, and is just trying to learn how to get started and it is very confusing to say:

“DON’T USE THIS SYNTAX.” “Example: wrap(THAT SYNTAX WE TOLD YOU NOT TO USE)”

Ok, my bad. Had left overs from previous experiments in alias section. Works nicely. Thanks.