如何解决参数数量不足或找不到条目。或者,运行“ webpack(-cli)--help”以获取使用信息

时间:2019-03-31 05:43:41

标签: webpack babel

运行命令Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info.时出现错误npm run dev,在此命令下我也收到一条错误消息,内容为ERROR in Entry module not found: Error: Can't resolve,后跟路径。我不太确定为什么它找不到切入点,将不胜感激。

将整个项目上载到github以帮助提高可视性。 https://github.com/dustinm94/coding-challenge

webpack.config.js

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
}

package.json

{
  "name": "coding_challenge",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development --watch ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js",
    "build": "webpack --mode production ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.0",
    "@babel/preset-env": "^7.4.2",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0"
  },
  "dependencies": {
    "babel-preset-react": "^6.24.1",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  }
}

.babelrc

{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": ["transform-class-properties"]
}

2 个答案:

答案 0 :(得分:1)

下面提到了要解决的问题

webpack.config.jspackage.json将始终位于项目的基本路径中,并且 节点命令应从此路径触发

您必须在webpack.config.jspackage.json

中进行以下更正

package.json

--watch将自动在entry的{​​{1}}对象中查找指定的文件,并继续观察其依赖关系图以在检测到更改时自动重新加载。您需要使用以下详细信息更新webpack.config.js

package.json

在监视模式下运行可能会导致性能问题,具体取决于您使用的硬件read more about it

webpack.config.js

"scripts": { "webpack" : "webpack", // invoke this command from npm run dev & npm run build "dev": "npm run webpack -- --mode development --watch", "build": "npm run webpack -- --mode production" } 对象添加到您的entry中。如果您没有覆盖输入对象,则默认情况下,Webpack会将webpack.config.js对象指向'。/ src / index.js`。由于您未在项目中使用默认配置,因此webpack会引发错误

entry

要解决此错误,您需要使用目标ERROR in Entry module not found: Error: Can't resolve './src' in '/root/../coding_challenge' 文件覆盖entry对象,如下所示

js

如果已完成上述更正,

module.exports = { entry : "./frontend/src/index.js", module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: "babel-loader" } } ] } } 将以监视模式运行项目

npm run dev将为您的项目生成生产版本

让我知道此信息是否可以解决您的问题

答案 1 :(得分:1)

我遇到了这个问题,并意识到名称webpack.config.js中包含空格字符。

enter image description here