How To Use Import Inside Eslintrc File?
Solution 1:
How to use import inside eslintrc file?
ESLint currently doesn't support a configuration file by the name of eslintrc
so I'm going to assume you mean .eslintrc.js
.
ESLint currently does not support ES Modules as you can see from the JavaScript (ESM) bullet item on their configuration file formats documentation.
If you are willing to install another dependency here is how you can use import
inside of .eslintrc.js
:
- Install the
esm
module,npm i esm -D
(Here I'm choosing as adevDependency
). - Create a new file as a sibling to
.eslintrc.js
called.eslintrc.esm.js
. - Inside of
.eslintrc.esm.js
include your ESLint configuration. Here you can useimport
and you should export your configuration asexport default { // Your config }
. - Inside
.eslintrc.js
include the following code:
const _require = require('esm')(module)
module.exports = _require('./.eslintrc.esm').default
Now you should be able to run eslint
as usual. A bit clunky with the extra file, but you can organize them in a directory if you like and use the --config
option of eslint
to point to the new location.
Solution 2:
You might notice that you are using the old syntax when exporting your object. You could try using require()
instead of import.
Alternatively, you could look into Shareable Configs.
Post a Comment for "How To Use Import Inside Eslintrc File?"