小编Tar*_*ell的帖子

如何修复“ERR_REQUIRE_ESM”错误?

我正在尝试使用 chalk npm。我的代码是:

     const chalk = require('chalk');

          console.log(
          chalk.green('All sytems go') +
          chalk.orange('until').underline +
          chalk.black(chalk.bgRed('an error occurred'))
           );
Run Code Online (Sandbox Code Playgroud)

当我输入 node main.js 时,我在终端中收到此错误

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/ezell/Documents/CodeX/NPM/node_modules/chalk/source/index.js from /Users/ezell/Documents/CodeX/NPM/main.js not supported.
Instead change the require of index.js in /Users/ezell/Documents/CodeX/NPM/main.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/ezell/Documents/CodeX/NPM/main.js:1:15) {
  code: 'ERR_REQUIRE_ESM'
}
Run Code Online (Sandbox Code Playgroud)

node.js npm chalk

12
推荐指数
3
解决办法
6万
查看次数

标签 统计

chalk ×1

node.js ×1

npm ×1