get-alex / alex

Catch insensitive, inconsiderate writing
https://alexjs.com
MIT License
4.81k stars 207 forks source link

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module when running Alex #325

Closed adrhumphreys closed 3 years ago

adrhumphreys commented 3 years ago

Subject of the issue

On a fresh install I'm getting these node issues with ES Imports, I haven't set up a config file and I can get these issues by creating a new repo

Your environment

Steps to reproduce

  1. mkdir alex && cd alex
  2. yarn init -y
  3. Add to package.json
    "scripts": {
    "lint": "alex"
    }
  4. Run yarn lint

Expected behaviour

Linting occurs

Actual behaviour

I get this funky error

$ alex
/Users/username/Code/alex/node_modules/alex/cli.js:12
var mdx = require('remark-mdx')
          ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/username/Code/alex/node_modules/remark-mdx/index.js from /Users/username/Code/alex/node_modules/alex/cli.js not supported.
Instead change the require of index.js in /Users/username/Code/alex/node_modules/alex/cli.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/username/Code/alex/node_modules/alex/cli.js:12:11) {
  code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.
wooorm commented 3 years ago

Thanks for reporting. Could you verify that it’s now solved?

plaindocs commented 3 years ago

Looks good to me. @wooorm thanks a ton!

❯ npm run lint

> docs@ lint /home/xxxx/Repositories/Buildkite/docs
> npx alex@9.1 -q --diff "pages/**/*.erb" "pages/**/*.txt"

npx: installed 316 in 29.608s