在使用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文件之后修改即可