Module not found: Error: Cannot resolve module

I have created a simple project which uses babel and webpack. I have checked it in here

https://github.com/abhitechdojo/MovieLensReact.git

In my root folder I have two files script1.js and script2.js. My webpack.config.js looks like

module.exports = {
    entry : {
        main: [
            'script1.js', 'script2.js'
        ]
    },
    output : {
        filename: 'public/main.js'
    },
    "module" : {
        "loaders" : [
            {
                "test": /\.jsx?/,
                "exclude": /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'react']
                }               
            }
        ]
    }
}

but when I run webpack. it cannot find any javascript files

ERROR in multi main
Module not found: Error: Cannot resolve module 'script1.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact
 @ multi main

ERROR in multi main
Module not found: Error: Cannot resolve module 'script2.js' in /Users/abhishek.srivastava/MyProjects/MovieLensReact
 @ multi main

In nodejs, when you call require("script1.js") it won’t search in the current folder.

You have to use require("./script2.js"), to specify that the file is in the current folder.

In your case, modify the config file with main: ['./script1.js', './script2.js'].


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   I can't get the html output from draft-js?

Similar Posts