webpack无法找到入口点

时间:2019-12-28 03:23:08

标签: webpack

我开始尝试使用webpack。

我正在关注Sitepoint的指南,该指南发布在此处:https://www.sitepoint.com/webpack-beginner-guide/

我正在使用以下package.json

{
  "name": "project-stub",
  "version": "0.1.0",
  "description": "",
  "main": "./src/js/main.js",
  "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
       "dev": "webpack --mode development",
      "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10"
  }
}

当我运行build或dev时,错误消息指示找不到'main.js'。 无论我将main.js放在项目根目录,src目录还是js目录中,这仍然适用。不管我如何编辑此配置的“ main”元素,它都是正确的。

典型错误如下:

 project-stub@0.1.0 build /home/bob/play/learning-react-2
> webpack --mode production


Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.

Hash: 43455f82066e07e4ac75
Version: webpack 4.41.5
Time: 40ms
Built at: 2019-12-28 16:19:32

ERROR in Entry module not found: Error: Can't resolve './src' in '/home/bob/play/learning-react-2'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project-stub@0.1.0 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the project-stub@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bob/.npm/_logs/2019-12-28T03_19_32_117Z-debug.log

如何告诉webpack我的源文件在哪里?

1 个答案:

答案 0 :(得分:0)

您可以通过在根目录中创建一个webpack.config.js并将其添加到代码中来告诉Webpack源文件在哪里。

module.exports = {
    entry: "./src/js"
};

您可以阅读有关配置here的更多信息。