生成的eslint.config.mjs:
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
export default [
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
package.json eslint 相关包:
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"eslint": "^9.3.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-formatter-summary": "^1.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-lit": "^1.13.0",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-wc": "^2.1.0",
"eslint-webpack-plugin": "^4.1.0"
一旦我在特定文件/文件夹上运行
eslint
,我就可以看到错误,规则/插件正在运行。但是,当我进入应用程序的构建应用程序阶段时:
[PluginError: [eslint] Cannot read config file: eslint.config.mjs
Error: end of the stream or a document separator is expected (7:19)
4 |
5 |
6 | export default [
7 | {languageOptions: { globals: globals.browser }},
-----------------------^
8 | pluginJs.configs.recommended,
9 | ...tseslint.configs.recommended,] {
plugin: 'webpack-stream',
showProperties: true,
showStack: false,
__safety: { toString: [Function: bound ] }
}
[19:04:14] assets by status 9.27 MiB [cached] 3 assets
ERROR in [eslint] Cannot read config file: eslint.config.mjs
Error: end of the stream or a document separator is expected (7:19)
4 |
5 |
6 | export default [
7 | {languageOptions: { globals: globals.browser }},
-----------------------^
8 | pluginJs.configs.recommended,
9 | ...tseslint.configs.recommended,
Webpack 配置(针对 webpack eslint 配置)是否应该使用最新的第 9 个 ESLint 版本进行更新?
webpack eslint 配置的配置:
new ESLintPlugin({
quiet: true,
failOnError: true,
outputReport: true,
overrideConfigFile: join(dirname, 'eslint.config.mjs'),
exclude: [
`model`,
`dist`,
`node_modules`,
`buildlocales`
]
}),
尝试将
configtype: "flat"
添加到您的 webpack eslint 插件中。根据文档,默认值仍然是 .eslintrc.json 文件。
我抛出了同样的错误,但这对我的微不足道的测试有用。