nrm 使用报错
报错内容:
internal/modules/cjs/loader.js:1093
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/local/lib/node_modules/nrm/node_modules/open/index.js
require() of ES modules is not supported.
require() of /usr/local/lib/node_modules/nrm/node_modules/open/index.js from /usr/local/lib/node_modules/nrm/cli.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/local/lib/node_modules/nrm/node_modules/open/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1093:13)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:782:14)
at Module.require (internal/modules/cjs/loader.js:965:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/usr/local/lib/node_modules/nrm/cli.js:9:14)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:782:14) {
code: 'ERR_REQUIRE_ESM'
那你应该使用的是: npm install -g nrm 命令进行的安装
原因:
应该使用 open 的 CommonJs 规范的包,现在 open v9.0.0 是 ES Module 版本的包
npm install -g nrm open@8.4.2