在学习node.js时安装全局工具nrm工具,尝试使用nrm ls命令查看可使用服务器,发现报错Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\hp\AppData\Roaming\npm\node_modules\nrm\cli.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (C:\Users\hp\AppData\Roaming\npm\node_modules\nrm\cli.js:9:14) {
code: 'ERR_REQUIRE_ESM'
}
通过自行阅读和网上大佬求解,发现是在安装目录的C:\Users\hp\AppData\Roaming\npm\node_modules\nrm\cli.js:9有问题,经过各种查找他人问题包括实行降低自己版本都不可用,发现一个靠谱的答案:
node-fetch
v3 最近停止了对 require
导入方式的支持,转而支持 ES 模块.您现在需要使用 ESM 导入,例如:
node-fetch
v3 recently stopped support for the require
way of importing it in favor of ES Modules. You'll need to use ESM imports now, like:
import fetch from "node-fetch";
然而也不行,最后无奈尝试注释掉目标文件问题行cli.js:9的//const open = require('open');最后成功了,也不知道以后有什么影响,希望对大佬能帮忙解决,并对一样有问题的伙伴有帮助。