解决npm安装nrm时的出错问题

在使用npm安装nrm时一般是全局安装,即执行以下代码
npm install nrm -g
一般是会安装成功,但执行以下命令时
nrm ls
无法显示其他安装源,并报以下的错误

PS G:\Echarts数据可视化\node.js> npm install -g nrm
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated coffee-script@1.7.1: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
C:\Users\Administrator\AppData\Roaming\npm\nrm -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\nrm\cli.js
+ nrm@1.2.1
updated 254 packages in 80.154s
PS G:\Echarts数据可视化\node.js> nrm ls
internal/validators.js:120
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

[TypeError [**ERR_INVALID_ARG_TYPE]**: The "path" argument must be of type string. Received undefined
  at validateString (internal/validators.js:120:11)
  at Object.join (path.js:375:7)
  at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\nrm\cli.js:17:20)
  at Module._compile (internal/modules/cjs/loader.js:1138:30)       
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
  at Module.load (internal/modules/cjs/loader.js:986:32)
  at Function.Module._load (internal/modules/cjs/loader.js:879:14)  
  **at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)**
  at internal/main/run_main_module.js:17:47
] {
  **code: 'ERR_INVALID_ARG_TYPE'**

错误代码太多,仅需看加粗部分,

解决办法:
打开cli.js并修改以下代码
const PKG = require('./package.json'); const NRMRC = path.join(process.env.HOME, '.nrmrc');
修改为

const NRMRC = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.nrmrc');

vscode则直接ctrl+单击即可进入cli.js文件之后修改即可

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值