Webpack 4 : ERROR in Entry module not found: Error: Can't resolve './src'

社会主义新天地 提交于 2019-11-30 14:33:40

问题


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'

回答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!




回答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',



回答3:


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




回答4:


As of webpack ^4.29.6 you don't need any configuration file so instead of giving path in package.json we need to write simply "build": "webpack" and keep index.js as entry point in src folder. However if you want to change entry point you can do so in webpack config file



来源:https://stackoverflow.com/questions/49772863/webpack-4-error-in-entry-module-not-found-error-cant-resolve-src

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!