sh: 1: webpack: 未找到

swo*_*wor 2 npm reactjs webpack

我正在开发 React+Django 应用程序 当我打电话时npm run dev

我收到一个错误

sh: 1: webpack: 未找到

npm ERR! Linux 4.4.0-197-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! frontend@1.0.0 dev: `webpack --mode development ./src/index.js --output ./static/frontend/main.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the frontend@1.0.0 dev script 'webpack --mode development ./src/index.js --output ./static/frontend/main.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the frontend package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack --mode development ./src/index.js --output ./static/frontend/main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs frontend
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls frontend
npm ERR! There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "frontend",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development ./src/index.js --output ./static/frontend/main.js",
    "build": "webpack --mode production ./src/index.js --output ./static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "description": ""
}
Run Code Online (Sandbox Code Playgroud)

发现在 . /node_modules/.bin/我只loose-envify -> ../loose-envify/cli.js* 读过这个问题Webpack command not found,但不明白如何修复我的错误。

Slb*_*box 6

您正在尝试使用webpack,但它没有列在 下devDependencies

在您的终端中,运行npm install --save-dev webpack然后重试。

我可能不会 100% 正确地使用该命令,因为我通常使用yarn该命令yarn add --dev webpack,但我 100% 确定这是您的问题。