报错信息:
internal/validators.js:124
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:124:11)
at Object.join (path.js:375:7)
at Object.<anonymous> (D:\nodejs\node_global\node_modules\nrm\cli.js:17:20)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 ] { code: 'ERR_INVALID_ARG_TYPE' }
npm安装nrm的时候经常会遇到下面这个报错,网上能搜到的解决方案一般是去将
C:\Users\RekTec\AppData\Roaming\npm\node_modules\nrm\cli.js
文件下 const NRMRC = path.join(process.env.HOME, '.nrmrc');
注释掉,并再添加一行,但是有时候会发现即使改了这个路径下的cli.js文件,但是依旧会报这个错误。
//const NRMRC = path.join(process.env.HOME, '.nrmrc'); (删除)
const NRMRC = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.nrmrc');
其实是因为每个人电脑配置所指向的cli文件不一致导致的,在我们使用
npm install nrm -g
安装完之后系统会立马反馈给我们有效的cli.js文件的路径,应该修改对应路径之下的cli.js文件。
在我安装的时候还遇到了一个和上面类似,但是报错信息是120的(上面是124,比较常见),120是因为node.js的版本与新安装的nrm版本不一致导致的,这种情况下有两个解决方案,一是安装最新版本的node.js。二是安装与自己node.js版本对应的nrm
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:124:11)
at Object.join (path.js:375:7)
at Object.<anonymous> (D:\nodejs\node_global\node_modules\nrm\cli.js:17:20)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 ] { code: 'ERR_INVALID_ARG_TYPE' }