我的 package.json 中有以下行
"scripts": {
"start": "cross-env NODE_ENV=development node index.js"
}
我可以看到“yarn start”命令运行正常,但是当我运行 直接在终端中执行“cross-env NODE_ENV=development node index.js”命令,出现以下错误:
zsh: command not found: cross-env
如果 cross-env 未在终端中注册,“yarn start”命令如何工作?
最佳答案
https://docs.npmjs.com/cli/v7/configuring-npm/folders#executables
When in local mode, executables are linked into ./node_modules/.bin so that they can be made available to scripts run through npm. (For example, so that a test runner will be in the path when you run npm test.)
这只是一项让事情变得更简单的功能。这也意味着,如果您正在与多人一起工作一个项目,您只需 npm install --save
一个模块——您不必担心项目中的每个人都在全局手动安装它.如果你想在命令行上自己运行它,你可以:
- 全局安装模块
- 在命令行中手动输入
./node_modules/.bin/cross-env
关于node.js - cross-env 命令在 nodejs 中如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69483812/