node.js - cross-env 命令在 nodejs 中如何工作?

标签 node.js npm node-modules yarnpkg cross-env

我的 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/

相关文章:

node.js - 如何将 fork 的 lerna 存储库的子包安装为 Node 依赖项?

node.js - 针对不同的 NODE_MODULE_VERSION 编译 - Tree-sitter 解析器、ATOM 包

react-native - "Module does not exist in the Haste module map"创建我自己的模块时

javascript - 将对象的参数转换为 Node 中的嵌套数组

angularjs - 在 AngularJS 和 NodeJS 中 stash API key 并推送到 Git 和 Heroku

node.js - 使用 Node js 在 mongodb 中过滤对象子对象

javascript - 使用 NightmareJS 时如何进行多个查询?

node.js - 'http-server' 未被识别为内部或外部命令

node.js - 如何抛出我自己的不显示调用堆栈的错误?

javascript - 无法在 AngularJS phonecat 应用程序中执行 Web 服务器