1

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.

Project Details:

  • Node.js Version: 18.18.1
  • TypeScript Version: 5.2.1
  • ESLint Version: 8.54.0

Relevant Configurations:

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';
  1. Ensured eslint-import-resolver-typescript is installed.
  2. Configured ESLint to use TypeScript's path resolutions.
  3. Restarted ESLint and the development environment.
  4. Verified the existence and correct path of 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"

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.