Reputation: 93
I am working on a Node.js project using TypeScript, and I have set up path aliases in my tsconfig.json
. However, ESLint is unable to resolve these path aliases, resulting in the error: Unable to resolve path to module '@/config.js'
. I've tried configuring ESLint to recognize the TypeScript path mappings, but the issue persists.
tsconfig.json:
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@sourceService/*": ["./src/modules/source/*"],
"@crawlService/*": ["./src/modules/crawl/*"],
"@searchService/*": ["./src/modules/search/*"],
"@/*": ["./src/*"]
},
// ... other options ...
},
"include": ["./src/**/*", "./test"]
}
.eslintrc.json:
{
"env": {
"node": true
},
// ... other configurations ...
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".js"]
},
"import/resolver": {
"node": true,
"typescript": {
"alwaysTryTypes": true,
"project": "./"
}
}
}
}
Example Import Statement Causing the Issue:
import { CONFIG } from '@/config.js';
eslint-import-resolver-typescript
is installed.src/config.js
.Despite these attempts, ESLint still fails to resolve the path aliases. Does anyone have suggestions on how to configure ESLint correctly to recognize TypeScript path aliases in this scenario?
Now everything building correctly, but I'm still getting this underscore error in this project, in other project with same packages, and config I do not get this errors. (the project it works is npm package with no server etc, just pure javascript / node with typescript and zod package (I wrote javascript/node because this package can be run on client and server side)
I can edit settings
to make them look like this:
"settings": {
"import/parsers": {
///////////////////
"node": {
"paths": ["src"],
"extensions": [".js", ".ts", ".d.ts", ".tsx"]
},
///////////////////
"@typescript-eslint/parser": [".ts", ".js"]
},
"import/resolver": {
"typescript": true,
"node": true
}
}
and underscore errors disappears but when I type
npx eslint --fix .
in my root dit then I recive this error saying:
TypeError: "settings" for node must be an array
Occurred while linting C:\Users\...
Rule: "import/default"
Upvotes: 1
Views: 1471
Reputation: 93
Closing and re-opening VSCode manuall did not work (It was re-opening project probably with some cache(?). It started working after opening fresh VSC instance.
Upvotes: 1