chalk / ansi-regex

Regular expression for matching ANSI escape codes
MIT License
185 stars 79 forks source link

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module #43

Closed smartameer closed 3 years ago

smartameer commented 3 years ago

Getting this issue while running any yarn task I have updated to 5.0.1 after yarn audit showed as a moderate fix.

Project Type: node express Node Version: 14.18.0 Usage: typescript Dependency: Internal to packages(eslint, nodemon, instana/collector)

      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/test/Practice/test/node_modules/ansi-regex/index.js
require() of ES modules is not supported.
require() of /Users/test/Practice/test/node_modules/ansi-regex/index.js from /Users/test/Practice/test/node_modules/wide-align/node_modules/strip-ansi/index.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 /Users/test/Practice/test/node_modules/ansi-regex/index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /Users/test/Practice/test/node_modules/ansi-regex/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/test/Practice/test/node_modules/wide-align/node_modules/strip-ansi/index.js:2:19)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

$ yarn audit
yarn audit v1.22.11

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ eslint                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ eslint > strip-ansi > ansi-regex                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1002401                     │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ eslint                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ eslint > table > string-width > strip-ansi > ansi-regex      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1002401                     │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ nodemon                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ nodemon > update-notifier > boxen > ansi-align >             │
│               │ string-width > strip-ansi > ansi-regex                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1002401                     │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @instana/collector                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @instana/collector > @instana/shared-metrics > node-gyp >    │
│               │ npmlog > gauge > wide-align > string-width > strip-ansi >    │
│               │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1002401                     │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │  Inefficient Regular Expression Complexity in                │
│               │ chalk/ansi-regex                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=5.0.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @instana/collector                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @instana/collector > @instana/autoprofile > node-gyp >       │
│               │ npmlog > gauge > wide-align > string-width > strip-ansi >    │
│               │ ansi-regex                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1002401                     │
└───────────────┴──────────────────────────────────────────────────────────────┘

Getting Lint error for the same

$ yarn lint --fix
yarn run v1.22.11
$ eslint src --ext .js,.ts,.tsx --fix
There was a problem loading formatter: /Users/test/Practice/test/node_modules/eslint/lib/cli-engine/formatters/stylish
Error: Must use import to load ES Module: /Users/test/Practice/test/node_modules/ansi-regex/index.js
require() of ES modules is not supported.
require() of /Users/test/Practice/test/node_modules/ansi-regex/index.js from /Users/test/Practice/test/node_modules/eslint/node_modules/strip-ansi/index.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 /Users/test/Practice/test/node_modules/ansi-regex/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/test/Practice/test/node_modules/ansi-regex/package.json.
sindresorhus commented 3 years ago

It sounds like you updated to v6.0.1 instead of v5.0.1.

sindresorhus commented 3 years ago

As for v6.0.1: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#readable-named-exports

smartameer commented 3 years ago

It sounds like you updated to v6.0.1 instead of v5.0.1.

yes with >=5.0.1 it auto installs 6.0.1 and that was giving problem. Now changed to work with ^5.0.1 Thank you.