当我尝试运行npm run build命令时出现很多错误

时间:2019-09-07 08:22:54

标签: ubuntu npm webpack

我正在尝试按照this教程进行Webpack设置,但是尝试运行命令时出现错误消息

npm run build

节点:v8.10.0

Ubuntu :18.04

错误

sh: 1: Webpack: not found
npm ERR! Linux 4.15.0-54-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! webpacks@1.0.0 build: `Webpack --mode development`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the webpacks@1.0.0 build script 'Webpack --mode development'.
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 webpacks package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     Webpack --mode development
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs webpacks
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls webpacks
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/webpacks/npm-debug.log

日志

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle webpacks@1.0.0~prebuild: webpacks@1.0.0
6 silly lifecycle webpacks@1.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle webpacks@1.0.0~build: webpacks@1.0.0
8 verbose lifecycle webpacks@1.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle webpacks@1.0.0~build: PATH: /usr/share/npm/bin/node-gyp-bin:/var/www/html/webpacks/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
10 verbose lifecycle webpacks@1.0.0~build: CWD: /var/www/html/webpacks
11 silly lifecycle webpacks@1.0.0~build: Args: [ '-c', 'Webpack --mode development' ]
12 info lifecycle webpacks@1.0.0~build: Failed to exec build script
13 verbose stack Error: webpacks@1.0.0 build: `Webpack --mode development`
13 verbose stack spawn ENOENT
13 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:17:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid webpacks@1.0.0
15 verbose cwd /var/www/html/webpacks
16 error Linux 4.15.0-54-generic
17 error argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 error node v8.10.0
19 error npm  v3.5.2
20 error file sh
21 error code ELIFECYCLE
22 error errno ENOENT
23 error syscall spawn
24 error webpacks@1.0.0 build: `Webpack --mode development`
24 error spawn ENOENT
25 error Failed at the webpacks@1.0.0 build script 'Webpack --mode development'.
25 error Make sure you have the latest version of node.js and npm installed.
25 error If you do, this is most likely a problem with the webpacks package,
25 error not with npm itself.
25 error Tell the author that this fails on your system:
25 error     Webpack --mode development
25 error You can get information on how to open an issue for this project with:
25 error     npm bugs webpacks
25 error Or if that isn't available, you can get their info via:
25 error     npm owner ls webpacks
25 error There is likely additional logging output above.
26 verbose exit [ 1, true ]

package.json

{
  "name": "webpacks",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "Webpack --mode development"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.39.3"
  }
}

我尝试按照here的建议使用npm i webpack -g全局安装webpack,但这没有帮助

我已经成功捆绑了一个main.js文件,该文件已保存在dist文件夹中,这是在我运行webpack-cli命令之后发生的,如果我对捆绑的文件进行更改,则在运行{{ 1}}

1 个答案:

答案 0 :(得分:1)

您必须将package.json中的webpack命令更改为小写而不是驼峰式,您正在构建脚本中编写Webpack

    "build": "webpack --mode development"