'Is it possible to setup eslint on webpack.config.babel.js without CommonJS warning/error?

As title. I want to use ES6 modules syntax on my webpack config file. Currently, I got:

Diagnostics:
Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi') [import/no-import-module-exports]


Solution 1:[1]

To use ES6 modules syntax in your webpack.config.js(and you don't need the .babel. in the middle), do the following:

  1. package.json add "type": "module"
  2. In webpack.config.js change Node.js module.exports to export default.
  3. In webpack.config.js change CJS __dirname,__filename to path.dirname(),import.meta.url with some modifications.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VimNing