Webpack 4 : ERROR in Entry module not found: Error: Can't resolve './src'
Solution 1
Resolved
Spent a lot of time to find out the solution.
Solution: Add index.js
file into src
folder.
That's it!.. solved :)
During Research, I found some facts about webpack 4 :
webpack 4 doesn’t need a configuration file by default!
webpack 4 there is no need to define the entry point: it will take ./src/index.js
as the default!
Solution 2
Met this problem when deploying on now.sh
Solution: Use Default Behavior
Move entry point to src/index.js
.
This leverage webpack@4
default value for entry
:
By default its value is
./src/index.js
, but you can specify a different (or multiple entry points) by configuring the entry property in the webpack configuration.
Solution: Be Specific
As @Lokeh pointed out, if you don't want to change your JS file location you can always use path.resolve()
in your webpack.config.js
:
entry: path.resolve(__dirname, 'src') + '/path/to/your/file.js',
Solution 3
Adding a context explicitly in webpack.config.js fixed issue for me. Adapt the following piece of code in your project:
context: __dirname + '/src',
entry: './index.js',
Solution 4
webpack ./src/js/app.js --output ./dist/app.bundle.js --mode development
This worked for me. I had the same trouble, it is because of a new version of webpack
Solution 5
I had a similar error and was able to resolve it with the command webpack src/index.js -o dist/bundle.js
the -o
did the trick. The issue wasn't the location of index.js it was missing the operator for defining the output path location.
See https://webpack.js.org/api/cli/
Version of webpack was 4.44.1
Sabir Hussain
I am a passionate Frontend / React developer with 6+ years of experience. Develops responsive, cross-browser compatible robust code. I'm good at React JS, Redux, Pixel perfect UI development and can do React Native development as well. I love Coffee, Listening Music & Travel to having an adventure, keen to help others, and share my knowledge and experience.
Updated on January 26, 2022Comments
-
Sabir Hussain over 2 years
I was trying to run webpack-4 first time
webpack ./src/js/app.js ./dist/app.bundle.js
it shows warning / error :
WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/ ERROR in multi ./src/js/app.js ./dist/app.bundle.js Module not found: Error: Can't resolve './dist/app.bundle.js' in 'D:\wamp64\www\webpack-4' @ multi ./src/js/app.js ./dist/app.bundle.js
Then i tried to change the mode
webpack --mode development
it shows :
ERROR in Entry module not found: Error: Can't resolve './src'
-
Lokesh Pandey over 5 yearswhat if you js file is at some location how would you define the path then or entry point ?
-
Lokesh Pandey over 5 years@MertMetin In case you don't want to change your js file location you can always use this answer. stackoverflow.com/questions/45255190/…
-
klewis over 4 yearsYour last solution helped me out, even with webpack reading custom .ejs files. Thanks
-
Mices almost 3 yearsI just built a new rails 6.1.3 app and there's no index.js anywhere
-
Onosa about 2 yearsSeeing how to use the merge command in combination with the env parameters was very helpful. Thank you.
-
Harlin about 2 yearsThanks! Good call. You probably saved me about an hour or so. :-D
-
deathknight256 almost 2 yearsThis solved my problem but I set my index file to be a typescript file.
entry: path.resolve(process.cwd(), './src/index.ts')
not sure why this is happening