ERROR in Entry module not found: ERROR: Can’t resolve ‘./ SRC ‘in XXX

The scene on pit

ERROR in Entry Module not found: ERROR: When using webpack command, ERROR in Entry module not found: Error: Can’t resolve ‘./ SRC ‘in XXX Error screenshots and project directories are as follows:

In baidu searching to find a solution, also have said after webpack version 4.0 can be packaged items do not need to use the configuration file (link: www.cnblogs.com/tassel/p/12.) . At that time, I was not sensitive to the key information of this solution, so when I used Google to search, I found the corresponding solution on Github. (Link: github.com/webpack/web…) . As shown in figure:

“Since v4.0.0, webPack no longer requires configuration files,” read webpack.js.org/concepts/.

Without configuration files, webpack is only valid if the SCR /index.js file is present. This information (in bold) is clearly identified in the document.

According to this comment, we click on this website, the text is as follows (if necessary, you can translate or enter this website to view) :

At its core, webpack is a static module bundler for modern JavaScript applications. When webpack processes your application, it internally builds a dependency graph whichmaps every module your project needs and generates one or more bundles. Learn more about JavaScript modules and webpack Modules here. Since version 4.0.0, webpack does not require a configuration file to bundle your project. it is incredibly configurable to better fit your needs.Copy the code

Since I used the configuration file to package the project with WebPack, I looked down for the official description of the configuration file configuration:

Entry
An entry point indicates which module webpack should use to begin building out its internal dependency graph. webpack will figure out which other modules and libraries that entry point depends on (directly and indirectly).

By default its value is , but you can specify a different (or multiple entry points) by setting an entry property in the webpack configuration. For example:./src/index.js
Copy the code

And here’s a sample code:

webpack.config.js

module.exports = {
  entry: './path/to/my/entry/file.js'
};
Copy the code

Then I went back to check my project structure and found that the filename of my configuration file was wrong! (What a stupid mistake, facepalm.)

It is explicitly stated that if a configuration file is used to package the project using Webpack, the file name is webpack.config.js. I wrote webpack-config.js as I used to do with configuration files. Therefore, the configuration file name is.config, not -config. Just change the file name.

I here again sum up my Baidu and Google search to the comprehensive solution!

The solution

  1. Check whether the entry configuration path is incorrect
  2. Check the path to webpack.config.js for error. Webpack.config. js must be in the root directory
  3. Check whether the configuration file name is incorrect. Yeswebpack.config.jsRather thanwebpack-config.js
  4. If the webPack version is v4.0.0 or later, you can use the webPack recommended on the official website instead of using the configuration file./src/index.jsAs an entry point