我有运行 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 中看到符号链接(symbolic link)
在本地,我可以执行 npm run 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 run 在包含冒号的目录中不起作用,因为 $PATH 是用冒号分隔的。
关于npm 脚本在 node_modules/.bin 中找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53194335/