[英]NPM-Scripts (in package.json) doesn't use the node_modules/.bin directory
我在 package.json 文件中有一些脚本:
"scripts": {
"build": "webpack --config webpack.config.prod.js --progress",
"dev": "webpack-dev-server --hot --config webpack.config.dev.js",
"test": "echo \"Error: no test specified\" && exit 1"
}
I installed the devDependencies in the package.json file (running the package.json in WebStorm) and npm created the ./node_modules/.bin/
directory with the needed binaries successfully.
问题是,当我运行npm run dev
来启动 webpack 服务器时:
sh:webpack-dev-server:找不到命令
我可以通过给出.bin
文件夹的确切路径来解决这个问题,如下所示:
"dev": "./node_modules/.bin/webpack-dev-server --hot --config webpack.config.dev.js"
我通过将.bin
添加到全局环境PATH中找到了另一种解决方案:
export PATH="$PATH:./node_modules/.bin"
我不能使用第一个解决方案,因为我不是一个人在这个项目中工作,而且他们没有问题。 此外,我读到,这应该是自己工作的(npm)。
第二种解决方案:我不想将项目包(二进制文件)添加到我的全局 PATH 环境中。
正常情况下,npm 可能会自动将
.bin
文件夹添加到环境路径中。
我想了解正在发生的事情(为什么它会自动对其他人起作用而不对我起作用?)
感谢您的阅读和帮助,我想我并不孤单:)。
我的 *./node_modules/.bin 路径中有一个“:”,但“:”用作 PATH 环境的分隔符(用于分隔二进制目录的不同路径)。 因此 shell 从未到达./node_modules/.bin目录,因为路径是这样的:
/Path/to/the/Project_19:20/node_modules/.bin
":" 是文件夹名称中出现斜线的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.