From 947d818950a64d031f0110eafcd4e93e9cfe49c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ann=20=E6=9D=8F=20Kilzer?= Date: Sat, 28 Feb 2026 12:44:18 +0900 Subject: [PATCH] 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 --- eslint.config.cjs | 75 ------------------------------------------- eslint.config.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 75 deletions(-) delete mode 100644 eslint.config.cjs create mode 100644 eslint.config.js diff --git a/eslint.config.cjs b/eslint.config.cjs deleted file mode 100644 index e0a9a05..0000000 --- a/eslint.config.cjs +++ /dev/null @@ -1,75 +0,0 @@ -const { - defineConfig, - globalIgnores, -} = require("eslint/config"); - -const globals = require("globals"); - -const { - fixupConfigRules, -} = require("@eslint/compat"); - -const tsParser = require("@typescript-eslint/parser"); -const reactRefresh = require("eslint-plugin-react-refresh"); -const stylistic = require("@stylistic/eslint-plugin"); -const js = require("@eslint/js"); - -const { - FlatCompat, -} = require("@eslint/eslintrc"); - -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all -}); - -module.exports = defineConfig([{ - languageOptions: { - globals: { - ...globals.browser, - }, - - parser: tsParser, - - parserOptions: { - project: ["tsconfig.json", "tsconfig.node.json"], - }, - }, - - extends: fixupConfigRules(compat.extends( - "eslint:recommended", - "plugin:@typescript-eslint/recommended-type-checked", - "plugin:react-hooks/recommended", - "plugin:react/recommended", - "plugin:react/jsx-runtime", - )), - - plugins: { - "react-refresh": reactRefresh, - "@stylistic": stylistic, - }, - - rules: { - "react-refresh/only-export-components": ["warn", { - allowConstantExport: true, - }], - - "react/react-in-jsx-scope": "off", - "quotes": ["error", "single"], - "@typescript-eslint/prefer-nullish-coalescing": "off", - "@typescript-eslint/no-unsafe-call": ["off"], - "@stylistic/indent": ["error", 4], - "@stylistic/semi": ["error", "never"], - "@stylistic/no-multi-spaces": "error", - "@stylistic/no-trailing-spaces": "error", - "@stylistic/no-mixed-spaces-and-tabs": "error", - "@typescript-eslint/no-explicit-any": "error", - }, - - settings: { - react: { - version: "detect", - }, - }, -}, globalIgnores(["**/dist", "**/eslint.config.cjs", "**/lighthouserc.cjs", "**/*.html", "**/coverage"])]); diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..39b6ad2 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,81 @@ +import { + defineConfig, + globalIgnores, +} from 'eslint/config' + +import globals from 'globals' + +import { + fixupConfigRules, +} from '@eslint/compat' + +import tsParser from '@typescript-eslint/parser' +import reactRefresh from 'eslint-plugin-react-refresh' +import stylistic from '@stylistic/eslint-plugin' +import js from '@eslint/js' + +import { + FlatCompat, +} from '@eslint/eslintrc' + +import path from 'path' +import { fileURLToPath } from 'url' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}) + +export default defineConfig([{ + languageOptions: { + globals: { + ...globals.browser, + }, + + parser: tsParser, + + parserOptions: { + project: ['tsconfig.json', 'tsconfig.node.json'], + }, + }, + + extends: fixupConfigRules(compat.extends( + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended-type-checked', + 'plugin:react-hooks/recommended', + 'plugin:react/recommended', + 'plugin:react/jsx-runtime', + )), + + plugins: { + 'react-refresh': reactRefresh, + '@stylistic': stylistic, + }, + + rules: { + 'react-refresh/only-export-components': ['warn', { + allowConstantExport: true, + }], + + 'react/react-in-jsx-scope': 'off', + 'quotes': ['error', 'single'], + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/no-unsafe-call': ['off'], + '@stylistic/indent': ['error', 4], + '@stylistic/semi': ['error', 'never'], + '@stylistic/no-multi-spaces': 'error', + '@stylistic/no-trailing-spaces': 'error', + '@stylistic/no-mixed-spaces-and-tabs': 'error', + '@typescript-eslint/no-explicit-any': 'error', + }, + + settings: { + react: { + version: 'detect', + }, + }, +}, globalIgnores(['**/dist', '**/eslint.config.js', '**/lighthouserc.cjs', '**/*.html', '**/coverage'])])