nrm工具配置淘宝镜像 Error [ERR_REQUIRE_ESM]: require() of ES Module ... code: ‘ERR_REQUI

414 阅读1分钟

我们在使用nrm工具进行配置淘宝镜像过程中使用cmd命令

nrm use taobao

image.png 结果出现这样的报错

C:\Windows\system32>nrm use taobao // 这里是我们在cmd 的指令
D:\nodejs\node_global\node_modules\nrm\cli.js:9
const open = require('open'); // 出现错误提示在(D:\nodejs\node_global\node_modules\nrm\cli.js:9:14)文件的第九行出现错误,说是require不支持,然后我们将cli.js中的require换成了import,保存后再次运行成功。
             ^
Error [ERR_REQUIRE_ESM]: require() of ES Module D:\nodejs\node_global\node_modules\nrm\node_modules\open\index.js from D:\nodejs\node_global\node_modules\nrm\cli.js not supported.
Instead change the require of index.js in D:\nodejs\node_global\node_modules\nrm\cli.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (D:\nodejs\node_global\node_modules\nrm\cli.js:9:14) {
  code: 'ERR_REQUIRE_ESM'
}

根据提示错误出现在(D:\nodejs\node_global\node_modules\nrm\cli.js:9:14)文件的第九行

我们查看下nrm\cli.js文件

image.png

nrm use taobao

image.png 即可完成配置。

在网上查找原因时,发现一个博主下的评论:

image.png

下面就是这个博主的博文:

 NodeJS 如何修复“ERR_REQUIRE_ESM”错误? _大数据知识库

也可能是Chalk版本的问题,不过大家要具体问题具体分析,这是我的一些见解。