get-alex/alex

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

adrhumphreys opened this issue · 2 comments

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

  • OS: OSX BigSur
  • Packages: "alex": "^9.1.0"
  • Env: Node v16.11.1 and Yarn 1.22.5

Steps to reproduce

  1. mkdir alex && cd alex
  2. yarn init -y
  3. Add to package.json
"scripts": {
  	"lint": "alex"
  }
  1. 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.

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

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