node.js - 安装 yarn 后 Npm 不工作(找不到 number-is-nan)

标签 node.js macos npm yarnpkg

我通过 brew 在我的 macOS 10.13 上安装了 yarn,yarn 工作正常。当我尝试使用 npm 时出现问题。我尝试运行的每个命令都出现以下错误:

gregor-mbp:~ gregor$ npm -v
module.js:471
    throw err;
    ^

Error: Cannot find module 'number-is-nan'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/node_modules/code-point-at/index.js:2:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

我尝试通过 yarn 将这个 number-is-nan 模块安装为全局模块,但没有成功。

现在我必须安装所有包并通过 yarn 运行脚本,这还不错,但我的项目有一些脚本可以通过 npm 运行其他脚本:

package.json 示例:

...
"scripts": {
  "start": "start-command",
  "build": "build-command",
  "development": "NODE_ENV=dev npm run build && npm run start",
  "production": "NODE_ENV=prod npm run build && npm run start"
},
...

当我运行 yarn development 时,我得到了与上面相同的错误。虽然我是开发团队中唯一安装了 yarn 的人,但我无法将配置更改为 yarn,因为其他人使用 npm。

所以我有什么解决办法,让 yarn 和 npm 可以在同一个系统上无错误地共存?或者我应该删除 yarn ?

最佳答案

尝试使用yarn重新安装npm:

yarn global add npm

关于node.js - 安装 yarn 后 Npm 不工作(找不到 number-is-nan),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47071160/

相关文章:

JavaScript - 遍历对象以查找特定键值

c++ - 哪个编译器用于生成 Microsoft Office for Mac?

ios - OS X Cocoa 颜色组合框

macos - 在 Mac 上进行 Delphi 开发的建议?

mysql - 我是sequelize的新手,如何将mysql查询转换为sequelize

java - 如何在接口(interface)中定义构造函数签名?

node.js - Homebrew npm 安装 : could not symlink

javascript - 使用 Angular 在 NgShoppingCart 中重新加载页面后,localStorage 中的项目被删除

node.js - 运行测试时 npm 错误 ELIFECYCLE

node.js - 如何在没有任何 babel 依赖的情况下发布 npm 模块?