eslint-webpack-plugin icon indicating copy to clipboard operation
eslint-webpack-plugin copied to clipboard

Cannot read config file: eslint.config.mjs.

Open kku39 opened this issue 1 year ago • 6 comments

Bug report

When I try webpack build, the following error occurs.

ERROR in [eslint] Cannot read config file: C:\dev\my-project\eslint.config.mjs
Error: end of the stream or a document separator is expected (32:62)

It looks like YAMLException, but my config file is mjs.

Some other people already reported the same problem on other projects as follows, but I think this is eslint-webpack-plugin's problem.

  • https://github.com/webpack/webpack/discussions/18434
  • https://github.com/eslint/eslint/issues/18514

Actual Behavior

ERROR in [eslint] Cannot read config file: C:\dev\my-project\eslint.config.mjs
Error: end of the stream or a document separator is expected (3:11)

 1 |
 2 | export default [{
 3 |   "no-var": 2
---------------^
 4 | }];

Expected Behavior

Lint works correctly, as same as executing npx eslint .

If you run my sample project, it is the expected behavior that eslint points out linting error of "no-var" at index.ts.

How Do We Reproduce?

  1. Clone my sample project: https://github.com/kku39/issue-repro-of-eslint-webpack-plugin
  2. npm ci
  3. npx webpack

Please paste the results of npx webpack-cli info here, and mention other relevant information (Edited)

$ npx webpack-cli info

  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
    Memory: 18.83 GB / 31.92 GB
  Binaries:
    Node: 20.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 127.0.6533.101
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  Packages:
    eslint-webpack-plugin: ^4.2.0 => 4.2.0
    webpack: ^5.93.0 => 5.93.0
    webpack-cli: ^5.1.4 => 5.1.4

kku39 avatar Aug 16 '24 04:08 kku39

@kku39 add configType as "flat" in the ESLint plugin option (https://webpack.js.org/plugins/eslint-webpack-plugin/#configtype), it solved for me

new ESLintPlugin({
      overrideConfigFile: path.resolve(__dirname, "eslint.config.mjs"),
      configType: "flat",
  });

Anasnew99 avatar Aug 16 '24 06:08 Anasnew99

@Anasnew99 It works for me too. Thanks...!

kku39 avatar Aug 16 '24 09:08 kku39

Now my trouble is settled by https://github.com/webpack-contrib/eslint-webpack-plugin/issues/263#issuecomment-2292928594 .

But since flat config is now the default in ESLint v9, so maybe eslint-webpack-plugin should follow suit.

Can anyone decide if it should be fixed or not?

Thanks.

kku39 avatar Aug 16 '24 09:08 kku39

@ricardogobbosouza Can we use flat when eslint version is 9 by default for better DX?

alexander-akait avatar Aug 16 '24 11:08 alexander-akait

@alexander-akait will be in version ^5.0.0

ricardogobbosouza avatar Aug 16 '24 12:08 ricardogobbosouza

@kku39 在 ESLint 插件选项 ( https://webpack.js.org/plugins/eslint-webpack-plugin/#configtype ) 中添加 configType 作为“flat”,它为我解决了

new ESLintPlugin({
      overrideConfigFile: path.resolve(__dirname, "eslint.config.mjs"),
      configType: "flat",
  });

oh my god, I looked at the configuration a few times and also noticed that it can use the old eslintrc configuration, but since the flat configuration is now the default in ESLint v9, I didn't notice that it was set to eslintrc by default. Thanks for your answer, it solved my problem.

luoshide avatar Aug 28 '24 12:08 luoshide

@alexander-akait will be in version ^5.0.0

Any update on v5? In my situation webpack configs are provided from external library where I can't update the plugin configs for just one single project.

avtarnanrey avatar Jan 09 '25 20:01 avtarnanrey

@ricardogobbosouza friendly ping, let's make a new major release, I think enough time has passed for this

Feel free to ping me (any) if this message hangs for a long time

alexander-akait avatar Feb 04 '25 12:02 alexander-akait

Released v5.0.0

ricardogobbosouza avatar Feb 26 '25 21:02 ricardogobbosouza