【问题标题】:All npm scripts fail, even though scripts themselves can run所有 npm 脚本都失败,即使脚本本身可以运行
【发布时间】:2019-02-16 17:42:35
【问题描述】:

我尝试在 npm 脚本上安装的任何 NPM 模块都会失败,例如 postinstall。 如果我以npm run postinstall 运行它,它也会失败。 如果我直接运行脚本 postinstall 调用(IE node whatever.js),它没有问题。不幸的是,这导致我无法安装任何使用 npm-scripts 的模块。

我创建了一个超级简单的包来显示问题。

{
  "name": "gahhh",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "postinstall": "node script.js"
  },
  "author": "",
  "license": "ISC"
}

script.js 包含:

'use strict';

console.log('Hello?');

运行输出:

C:\Workspace\testing>npm run postinstall

> gahhh@1.0.0 postinstall C:\Workspace\testing
> node script.js

npm ERR! file bash
npm ERR! path bash
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn bash
npm ERR! gahhh@1.0.0 postinstall: `node script.js`
npm ERR! spawn bash ENOENT

详细错误输出:

C:\Workspace\testing>npm run postinstall --verbose
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\USERNAME\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'run',
npm verb cli   'postinstall',
npm verb cli   '--verbose' ]
npm info using npm@6.8.0
npm info using node@v10.15.1
npm verb run-script [ 'postinstall' ]
npm info lifecycle gahhh@1.0.0~postinstall: gahhh@1.0.0

> gahhh@1.0.0 postinstall C:\Workspace\testing
> node script.js

npm verb lifecycle gahhh@1.0.0~postinstall: unsafe-perm in lifecycle true
npm verb lifecycle gahhh@1.0.0~postinstall: PATH: C:\Users\USERNAME\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Workspace\testing\node_modules\.bin;c:\program files\graphicsmagick-1.3.31-q16;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Program Files\maven\bin;C:\Program Files\PuTTY\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\nodejs\;C:\Users\USERNAME\.windows-build-tools\python27\;C:\Users\USERNAME\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\USERNAME\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\.bin;C:\Users\USERNAME\AppData\Roaming\npm\node_modules\.bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\RSA SecurID Token Common;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;C:\Program Files (x86)\WebEx\Productivity Tools;C:\Program Files (x86)\WebEx\PTools020000000;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Program Files\nodejs\;C:\Program Files\maven\bin;C:\Program Files\PuTTY\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Users\USERNAME\AppData\Local\Microsoft\WindowsApps;C:\Users\USERNAME\AppData\Roaming\Composer\vendor\bin;C:\Users\USERNAME\AppData\Roaming\npm
npm verb lifecycle gahhh@1.0.0~postinstall: CWD: C:\Workspace\testing
npm info lifecycle gahhh@1.0.0~postinstall: Failed to exec postinstall script
npm info lifecycle gahhh@1.0.0~postinstall: Failed to exec postinstall script
npm verb stack Error: gahhh@1.0.0 postinstall: `node script.js`
npm verb stack spawn bash ENOENT
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
npm verb stack     at onErrorNT (internal/child_process.js:415:16)
npm verb stack     at process._tickCallback (internal/process/next_tick.js:63:19)
npm verb pkgid gahhh@1.0.0
npm verb cwd C:\Workspace\testing
npm verb Windows_NT 10.0.14393
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\USERNAME\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "postinstall" "--verbose"
npm verb node v10.15.1
npm verb npm  v6.8.0
npm ERR! file bash
npm ERR! path bash
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn bash
npm ERR! gahhh@1.0.0 postinstall: `node script.js`
npm ERR! spawn bash ENOENT
npm ERR!
npm ERR! Failed at the gahhh@1.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm timing npm Completed in 230ms

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\USERNAME\AppData\Roaming\npm-cache\_logs\2019-02-16T17_36_05_033Z-debug.log

如果我运行node script.js,我会得到预期的输出,所以此时我正用头撞我的桌子。我的想法已经用完了。

节点版本:v10.15.1 npm 版本:6.8.0

【问题讨论】:

标签: node.js npm npm-scripts


【解决方案1】:

经过很长时间的搜索,显然shell=bash 是如何进入我的.npmrc 文件的。由于我使用的是 Windows,bash 对我不起作用。删除此行完全解决了问题。

我想我会分享这个,以防其他人遇到这个问题。

【讨论】:

  • 是的,同样的事情发生在我身上,问题是重新安装 npm 并没有解决,卸载 npm 后这些文件仍然存在,更多信息请查看github.com/npm/cli
  • 我已经为此寻找了好几天,但没有一个解决方案来解决这个问题。!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-19
  • 1970-01-01
相关资源
最近更新 更多