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-remended',
'plugin:@typescript-eslint/remended',
'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 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-remended',
'plugin:@typescript-eslint/remended',
'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.
Share Improve this question edited Mar 20, 2020 at 15:18 ROOT 11.6k5 gold badges34 silver badges48 bronze badges asked Mar 20, 2020 at 15:01 MickMick 8,95110 gold badges49 silver badges70 bronze badges 1-
You need to explicitly mention the path of your node_modules folder. either one will be worked
../node_modules/@typescript-eslint/parser
/node_modules/@typescript-eslint/parser
/node_modules/@typescript-eslint/parser
node_modules/@typescript-eslint/parser
same for other node module dependencies. – Farzam Babar Commented Feb 16, 2021 at 13:12
1 Answer
Reset to default 4I ended up contacting the ESLint discord help, and found some resources there that helped me set up a shared config.
https://github./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./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/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...