Skip to content

Fix an error in local environments where running npm run lint shows…#293

Open
ann-kilzer wants to merge 1 commit intomainfrom
eslint-es-module-format
Open

Fix an error in local environments where running npm run lint shows…#293
ann-kilzer wants to merge 1 commit intomainfrom
eslint-es-module-format

Conversation

@ann-kilzer
Copy link
Collaborator

What changed 🧐

Fix an error in local environments where running npm run lint shows an error like:

ESLint: 9.37.0

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/annkilzer/dev/womeninsoftwarejp/home/node_modules/@stylistic/eslint-plugin/dist/index.js from /Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs not supported. Instead change the require of index.js in /Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs to a dynamic import() which is available in all CommonJS modules. at Object. (/Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs:14:19)

The solution is to use EcmaScript module format rather than a Common JS file.

Used GitHub Copilot to make this change

How did you test it? 🧪

locally please run

# ensure you're using the right node version
nvm use
# update deps
npm i
# check the linter and ensure no errors
npm run lint

… an error like:

ESLint: 9.37.0

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/annkilzer/dev/womeninsoftwarejp/home/node_modules/@stylistic/eslint-plugin/dist/index.js from /Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs not supported.
Instead change the require of index.js in /Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/annkilzer/dev/womeninsoftwarejp/home/eslint.config.cjs:14:19)

The solution is to use EcmaScript module format rather than a Common JS file.

Used GitHub Copilot to make this change
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR resolves an ESLint runtime error in local environments caused by loading an ESM-only plugin (@stylistic/eslint-plugin) from a CommonJS ESLint flat config.

Changes:

  • Replaced the CommonJS flat config (eslint.config.cjs) with an ESM flat config (eslint.config.js) using import/export.
  • Added ESM-compatible __dirname handling via fileURLToPath(import.meta.url) for FlatCompat’s baseDirectory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
eslint.config.js New ESM flat config to prevent require()-of-ESM errors when loading ESM-only ESLint plugins.
eslint.config.cjs Removed prior CommonJS flat config that triggered the local lint failure.

@RossellaFer
Copy link
Contributor

@ann-kilzer was the error showing when you run the Node version from main?
I can't replicate the issue, so I am unsure how to test it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants