npm 脚本在 node_modules/.bin 中找不到文件
npm scripts don't find files in node_modules/.bin
我有 运行 webpack
的 npm 脚本
"scripts": {
"build": "webpack --display-error-details --progress --config webpack.dev.config.js",
"build:prod": "webpack --display-error-details --config webpack.prod.config.js",
}
Webpack 安装正常,我可以在 node_modules/.bin
中看到符号链接
我可以在本地执行 npm 运行 build 并且它可以工作,但是在生产服务器上它失败了:
/bin/sh: 1: webpack: not found
我可以 运行 node_modules/.bin/webpack 一切正常。
npm config ls 的输出看起来与本地和服务器几乎相同(相同的 npm 和节点版本)
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.4.1 node/v8.10.0 linux x64"
; userconfig /home/ubuntu/.npmrc
script-shell = "/bin/sh"
; builtin config undefined
globalconfig = "/etc/npmrc"
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"
; node bin location = /usr/bin/node
我在这里错过了什么?
归根结底,这是因为 npm 运行 在包含冒号的目录中不起作用,因为 $PATH 是用冒号分隔的。
我有 运行 webpack
的 npm 脚本"scripts": {
"build": "webpack --display-error-details --progress --config webpack.dev.config.js",
"build:prod": "webpack --display-error-details --config webpack.prod.config.js",
}
Webpack 安装正常,我可以在 node_modules/.bin
中看到符号链接我可以在本地执行 npm 运行 build 并且它可以工作,但是在生产服务器上它失败了:
/bin/sh: 1: webpack: not found
我可以 运行 node_modules/.bin/webpack 一切正常。
npm config ls 的输出看起来与本地和服务器几乎相同(相同的 npm 和节点版本)
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.4.1 node/v8.10.0 linux x64"
; userconfig /home/ubuntu/.npmrc
script-shell = "/bin/sh"
; builtin config undefined
globalconfig = "/etc/npmrc"
globalignorefile = "/etc/npmignore"
prefix = "/usr/local"
; node bin location = /usr/bin/node
我在这里错过了什么?
归根结底,这是因为 npm 运行 在包含冒号的目录中不起作用,因为 $PATH 是用冒号分隔的。