【问题标题】:npm scripts don't find files in node_modules/.binnpm 脚本在 node_modules/.bin 中找不到文件
【发布时间】:2019-04-11 04:05:16
【问题描述】:

我有运行 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 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 webpack npm-scripts


    【解决方案1】:

    归根结底,这是因为 npm run 在包含冒号的目录中不起作用,因为 $PATH 是用冒号分隔的。

    npm issue here

    【讨论】:

    • 追了三个月这个bug,就是这样。我不敢相信。我以为我的整个 npm 安装被破坏并重新安装了 3 次,并且即将完全放弃。非常感谢您发布这个答案!!!
    猜你喜欢
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 2019-10-28
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多