nrm 安装后报错 Error [ERR_REQUIRE_ESM]: require() of ES Module

  • 安装 nrm 后,进行使用时报错

    $ npm i -g nrm
    
    /Users/xxx/.nvm/versions/node/v16.20.0/lib/node_modules/nrm/cli.js:9  
    const open = require('open');  
    ^  
    
    Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/xxx/.nvm/versions/node/v16.20.0/lib/node_modules/nrm/node_modules/open/index.js from /Users/lixiaoxia/.nvm/versions/node/v16.20.0/lib/node_modules/nrm/cli.js not supported.  
    Instead change the require of index.js in /Users/xxx/.nvm/versions/node/v16.20.0/lib/node_modules/nrm/cli.js to a dynamic import() which is available in all CommonJS modules.  
    at Object.<anonymous> (/Users/xxx/.nvm/versions/node/v16.20.0/lib/node_modules/nrm/cli.js:9:14) {  
    code: 'ERR_REQUIRE_ESM'  
    }
    
  • 原因:应该使用 openCommonJs 规范的包,现在 open v9.0.0ES Module 版本的包。

  • 解决方案:

    $ npm i -g nrm [email protected] --save
    

猜你喜欢

转载自blog.csdn.net/zz00008888/article/details/130750480