【问题标题】:npm - error running package.jsonnpm - 运行 package.json 时出错
【发布时间】:2015-09-02 02:29:15
【问题描述】:

我正在学习 nodejs 并尝试构建一个简单的控制台应用程序。该应用程序正在运行。但是,当我运行下面的 package.json 以便我可以轻松地构建它并安装所有依赖项时,出现了一些错误。看起来它无法安装依赖项,因为如果我先安装依赖项,就不会有问题。有谁知道我的 package.json 出了什么问题?

谢谢。

{
  "name": "Testing",
  "version": "0.0.1",
  "author": "My Name",
  "description": "testing",
  "scripts": {
    "build-js": "browserify scripts/app.js > scripts/bundle.js"
  },
  "dependencies": {
    "browserify": "*",
    "uniq": "*"
  }
}

当我运行npm run build-js 时,出现以下错误:

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\node
\\node_modules\\npm\\bin\\npm-cli.js" "run" "build-js"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! Testing@0.0.1 build-js: `browserify scripts/app.js > scripts/bundle.j

npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Testing@0.0.1 build-js script 'browserify scripts/app.j
> scripts/bundle.js'.
npm ERR! This is most likely a problem with the Testing package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     browserify scripts/app.js > scripts/bundle.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls Testing
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\vinh.ngo\Desktop\react-play\npm-debug.log

我的 npm-debug.log 是

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build-js' ]
2 info using npm@2.7.4
3 info using node@v0.12.2
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose run-script [ 'prebuild-js', 'build-js', 'postbuild-js' ]
6 info prebuild-js Testing@0.0.1
7 info build-js Testing@0.0.1
8 verbose unsafe-perm in lifecycle true
9 info Testing@0.0.1 Failed to exec build-js script
10 verbose stack Error: Testing@0.0.1 build-js: `browserify scripts/app.js > scripts/bundle.js`
10 verbose stack Exit status 1
10 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:213:16)
10 verbose stack     at EventEmitter.emit (events.js:110:17)
10 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:14:12)
10 verbose stack     at ChildProcess.emit (events.js:110:17)
10 verbose stack     at maybeClose (child_process.js:1015:16)
10 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
11 verbose pkgid Testing@0.0.1
12 verbose cwd C:\Users\vinh.ngo\Desktop\react-play
13 error Windows_NT 6.1.7601
14 error argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build-js"
15 error node v0.12.2
16 error npm  v2.7.4
17 error code ELIFECYCLE
18 error Testing@0.0.1 build-js: `browserify scripts/app.js > scripts/bundle.js`
18 error Exit status 1
19 error Failed at the Testing@0.0.1 build-js script 'browserify scripts/app.js > scripts/bundle.js'.
19 error This is most likely a problem with the Testing package,
19 error not with npm itself.
19 error Tell the author that this fails on your system:
19 error     browserify scripts/app.js > scripts/bundle.js
19 error You can get their info via:
19 error     npm owner ls Testing
19 error There is likely additional logging output above.
20 verbose exit [ 1, true ]

在运行npm run build-js之前是否必须先运行npm install才能安装所有依赖项?

【问题讨论】:

  • C:\Users\vinh.ngo\Desktop\react-play\npm-debug.log 中有什么?
  • 嗨,Suresh,我刚刚添加了我的 npm-debug.log
  • 删除那些依赖项,然后首先运行npm install browserify --save 和npm install uniq --save,因为看起来你是手工编写的,依赖版本号不是这样工作的。如果你是手工做的,你仍然需要使用 semver 格式。所以不要手动操作。
  • * 是依赖版本@Mike'Pomax'Kamermans 的有效值。看看npm help json。
  • @Mike'Pomax'Kamermans 感谢您的建议!

标签: node.js npm browserify


【解决方案1】:

我感觉是重定向 (&gt;) 导致了这里的问题,要么是因为命令在后台执行的方式,要么是因为您尝试将输出重定向到的文件已经存在。

您可能应该改用browserify 的--outfile/-o 选项:

"scripts": {
    "build-js": "browserify scripts/app.js -o scripts/bundle.js"
},

【讨论】:

  • 我以前试过这个,但也没有用。我必须先运行npm install,然后运行npm run build-js 才能让它工作。不知道是不是这样?
  • 你每次都要运行npm install?
  • 只需运行一次即可安装所有依赖项。之后,因为这些依赖项已经存在,run build-js 将起作用。
  • 是的,这就是 NPM 的工作方式。如果您不运行npm install,则未安装 Browserify,如果未安装 Browserify,您将无法运行 browserify(npm run 也无法运行)。
猜你喜欢
  • 2016-03-04
  • 2018-11-22
  • 1970-01-01
  • 2020-11-08
  • 2018-08-18
  • 2021-07-02
  • 2014-08-01
  • 2018-11-13
相关资源
最近更新 更多