I have multiple apps that I would like to share the same eslint config:
- project_root/
- app1/
- node_modules/
- eslint.rc
- app2/
- node_modules/
- eslint.rc
- app3/
- node_modules/
- eslint.rc
- eslint.rc
Each app has the same config:
module.exports = {
extends: [
'../.eslintrc',
],
};
And in the root I want to have everything configured:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {},
};
But now every app throws error that it cant find the node modules:
Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.js » ../.eslintrc': Cannot find module '@typescript-eslint/parser'`.
I don't have any node_modules in the root and I would like to avoid it.
I ended up contacting the ESLint discord help, and found some resources there that helped me set up a shared config.
https://github.com/eslint/eslint/issues/3458
As I'm using RushJS to manage my monorepo, I'm using a patch to ESLint to allow a shared-config npm package to load plugins locally. More info here: https://www.npmjs.com/package/@rushstack/eslint-patch.
In short, create an NPM package in your monorepo - you don't have to upload this to NPM if you link locally (RushJS does this, but I think you can do this with plain NPM too). Put your config in that package - info here: https://eslint.org/docs/user-guide/configuring/configuration-files#using-a-shareable-configuration-package Add any plugins referenced from your shared config as dependencies of that package. Using the eslint-patch referenced above, ESLint will load the plugins from this package, rather than you having to install them in each project.
This worked for me. I hope it helps others...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With