0

我是 Webpack 的新手,我一直在关注他们的文档 https://webpack.js.org/guides/getting-started/

为了构建我的第一个简单代码并使用 webpack 构建它

在最后一节中,我必须将构建命令添加到 package.json 中的脚本

    {
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack --config webpack.config.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.2"
  },
  "dependencies": {
    "lodash": "^4.17.11"
  }
}

我跑npm run build我得到了错误

npm run build

> webpack-demo@1.0.0 build /Users/test/Desktop/Devolopment/webpack-demo
> webpack --config webpack.config.js

sh: webpack: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! webpack-demo@1.0.0 build: `webpack --config webpack.config.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the webpack-demo@1.0.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!     /Users/test/.npm/_logs/2019-03-20T04_11_16_661Z-debug.log

有人可以帮助我为什么,请记住,我完全按照文档中使用的相同包版本来遵循文档

此致

4

1 回答 1

1

我意识到我必须在全球范围内安装webpackwebpack-cli

现在它工作正常。

太感谢了。

于 2019-03-20T09:04:56.073 回答