I have a monorepo in which I'm utilizing node. When running npx eslint .
, I am still getting errors with both my Node server subdir and my React client subdir, like the following:
warning: Unable to resolve path to module 'react' import/no-unresolved
Ideal behavior is that I am able to run npx eslint --fix .
from anywhere in my repo and it will automatically fix any non absolute import paths. I do not want any paths to have import {} from 'client/src'
or import {} from 'server/src'
etc.
Here is my directory structure:
╭─ mycomputer ~/Documents/code/repo ‹branch*›
╰─➤ tree -L 2
.
├── README.md
├── client
│ ├── Dockerfile
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ ├── src
│ └── tsconfig.json
├── node_modules
├── package-lock.json
├── package.json
└── server
├── Dockerfile
├── README.md
├── node_modules
├── package-lock.json
├── package.json
├── prisma
├── src
├── test
└── tsconfig.json
Here is my .eslintrc located in my root directory repo
.
// .eslintrc
{
"env": {
"node": true,
"commonjs": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import", "no-relative-import-paths"],
"extends": [
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"settings": {
"import/resolver": {
"typescript": {
"project": [
"server/tsconfig.json",
"client/tsconfig.json"
]
},
"node": {
"moduleDirectory": [
"client/src/",
"node_modules/",
"server/src/",
"server/node_modules/"
],
"extensions": [".ts", ".tsx", ".native.js"]
}
}
},
"rules": {
"import/order": [
"warn",
{
"alphabetize": {
"caseInsensitive": true,
"order": "asc"
},
"groups": [["builtin", "external"]],
"newlines-between": "always"
}
],
"import/no-unresolved": [1, {"commonjs": false, "amd": false}],
"import/default": "off",
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-relative-import-paths/no-relative-import-paths": [
"warn",
{ "allowSameFolder": true }
]
},
"root": true
}
Here is my client/tsconfig.json:
╰─➤ cat client/tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es5"
},
"include": ["src"]
}
Here is my server/tsconfig.json:
╰─➤ cat server/tsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"esModuleInterop": true,
"lib": ["esnext"],
"outDir": "dist",
"sourceMap": true,
"strict": true
},
"include": ["src"]
}
Any thoughts on what I have specified incorrectly?