question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[HELP] Can not get plugin to work with path aliases

See original GitHub issue

Hi there,

Sorry if this is a situation where I am being dense – most likely the case. I have spent the last couple hours trying to get the plugin to work but to no avail.

I have search previous questions here and on Stack Overflow but I just can’t find any solution which makes eslint play ball with my typescript paths.

Basically, it always gives me an error if I import a module via its mapped alias in the tsconfig file. If I change it to a relative path it is fine. Typescript has no issues finding the modules it is just eslint being a pain.

Some code

// tsconfig.json
...
    "baseUrl": "src",
    "paths": {
      "@services/*": ["services/*"],
      "@constants/*": ["constants/*"],
      "@typeDefs/*": ["typeDefs/*"],
      "@config/*": ["config/*"],
      "@utils/*": ["utils/*"],
      "@assets/*": ["assets/*"]
    }
...

// Eslint config
...
  "plugins": ["@typescript-eslint", "prettier", "import"],
  "extends": [
    "airbnb-base",
    "airbnb-typescript/base",
    "prettier",
    "eslint:recommended",
    "plugin:import/typescript",
    "plugin:import/recommended",
    "plugin:node/recommended"
  ],
  "parserOptions": {
    "ecmaVersion": 2021,
    "sourceType": "module",
    "project": "tsconfig.json"
  },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts"]
    },
    "import/resolver": {
      "typescript": {
        "alwaysTryTypes": true,
        "project": "tsconfig.json"
      }
    },
    "node": {
      "tryExtensions": [".ts"]
    }
  }
...

And I am importing as follows:

import { someFunc } from "@services/index";

Further info: Node version: v14.20.0 NPM version: 8.14.0

All packages have been downloaded today so they are all the latest.

Sorry again if I am being dense I am just at wits end. Thank you in advance

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
JounQincommented, Jul 22, 2022
/workspace/help/__tests__/dummy.test.ts
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: __tests__/dummy.test.ts.
The file must be included in at least one of the projects provided

/workspace/help/src/index.ts
  1:22  error  "@services/index" is not found  node/no-missing-import

I don’t find any issue related to this resolver.

node/no-missing-import should just be disabled when using together with eslint-plugin-import because it is redundant.

2reactions
MakingStuffscommented, Jul 22, 2022

No probs thank you for responding so quickly I really appreciate it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage with path aliases · Issue #96 · wessberg/rollup-plugin-ts
I'm currently building an external UI kit containing React components, fonts and SCSS stylesheets for use in CRA and Next.js apps. Relative ...
Read more >
Typescript — How to solve the problem with unresolved path ...
The actual cause of the issue is that the tsc compiler does not transpiles correctly the path aliases to absolute (real) paths.
Read more >
Why does VSCode not pick up path aliases in tsconfig?
Update 1: I only have this issue with files ending in .js . If I rename them to .ts everything works fine. Weirdly...
Read more >
Path aliases with TypeScript in Node.js - DEV Community ‍ ‍
I have a library with hundreds of tests but right now none of them run because I'm using Mocha/Chai with ts-node and I'm...
Read more >
How to handle tsconfig path aliases : r/typescript - Reddit
I've hit the ageold "Failed to load module..." error, where it can't resolve my path alias of "@something". I was using the Live...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found