npm 脚本在 node_modules/.bin 中找不到文件

标签 npm webpack npm-scripts

我有运行 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 issue here

关于npm 脚本在 node_modules/.bin 中找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53194335/

相关文章:

javascript - React 项目中 webpack.config.js 放在哪里?

javascript - WebStorm eslint-config-标准错误

node.js - 本地隧道替代方案不起作用

reactjs - npm ERR!找不到404-GET https://registry.npmjs.org/@typescript-eslint%2feslint-plugin-找不到

angular - 'L' 引用 UMD 全局 - 编译错误

node.js - npm package.json 操作系统特定脚本

node.js - 如何修复这个 package.json 文件中的 NPM EJSONParse?

javascript - 我在 webpack.DefinePlugin 中定义的变量未定义

npm - 如何在package.json中动态选择包管理器

node.js - 您可以在 package.json 中为 npm 脚本设置别名吗?