Closed JusticHentai closed 2 months ago
Please provide more information, esm can load cjs AFAIK.
@JounQin
config
import js from '@eslint/js'
import json from '@eslint/json'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import globals from 'globals'
import tsEslint from 'typescript-eslint'
import eslintPluginPrettier from 'eslint-plugin-prettier/recommended'
const tsConfig = tsEslint.config({
extends: [
js.configs.recommended,
...tsEslint.configs.recommended,
eslintPluginPrettier,
],
files: ['**/*.{js,ts,tsx}'],
ignores: ['dist'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
})
const jsonConfig = {
files: ['**/*.json'],
plugins: {
json,
},
language: 'json/json',
rules: {
'json/no-duplicate-keys': 'error',
},
}
export default [...tsConfig, jsonConfig]
error
Oops! Something went wrong! :(
ESLint: 9.9.0
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
The error doesn't show it's caused by eslint-plugin-prettier
?
@JounQin 我一个个依赖扒了下 这里只有 eslint-plugin-prettier 是 module.export,去掉后就没有报错了,这里的报错是 package.json -> type: module 检测到非 esm 报错了,地址在这里 https://github.com/JusticHentai/eslint-config
@JounQin 刚刚详细排查了下 是我的 prettier 引用到了一些旧的依赖导致的问题😂抱歉 浪费了时间
What version of
eslint
are you using?9.9.0
What version of
prettier
are you using?3.3.3
What version of
eslint-plugin-prettier
are you using?5.2.1
Please paste any applicable config files that you're using (e.g.
.prettierrc
or.eslintrc
files)What source code are you linting?
What did you expect to happen?
eslint-plugin-prettier support esm
What actually happened?
eslint-plugin-prettier only support cjs