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.

`paths` not used for auto import

See original GitHub issue

From https://github.com/Microsoft/vscode/issues/72931

TypeScript Version: 3.5.0-dev.20190430

Search Terms:

  • paths
  • auto import

Repo

  1. clone https://github.com/ac566/typescript-auto-import-issue and open in vscode
  2. In VS Code, set "typescript.preferences.importModuleSpecifier": "non-relative"
  3. Open src/app/app1/test.ts
  4. Delete the import for TestType
  5. Try using a quick fix or auto import to add the impact back

Expected behavior: The import is added as import { TestType } from "@myLib/example_2";

The is expected since the tsconfig configures paths and the import of @myLib/example_2 was previously working properly:

{
    "compilerOptions": {
        "target": "es5",
        "module": "es2015",
        "moduleResolution": "node",
        "baseUrl": ".",
        "paths": {
            "@myLib/*": [
                "./src/lib/src/*/_index.ts"
            ]
        }
    }
}

Actual behavior: The import is added as import { TestType } from "@myLib/example_2/_index";

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:15
  • Comments:9

github_iconTop GitHub Comments

2reactions
nautilorcommented, Jan 18, 2021

In my case just by using in my settings

"typescript.preferences.importModuleSpecifier": "non-relative",

and then setting in my tsconfig compilerOptions.paths my root as the last options I was able to import files using path correctly

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@model/*": ["src/model/*"],
      "@route/*": ["src/route/*"],
      "@constant/*": ["src/constant/*"],
      "@/*": ["src/*"]
    }
  },
}

This creates

import { JWT_CONFIG } from "@constant/jwt";

instead of

import { JWT_CONFIG } from "./constant/jwt";

or

import { JWT_CONFIG } from "@/constant/jwt";

which is what i was looking for.

2reactions
WanderWangcommented, Oct 29, 2019

I got a same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code auto imports not using absolute paths and not indented
When I type something that can be auto imported, as seen in the above GIF, the auto import doesn't keep things at the...
Read more >
Auto-import does not use always tsconfig path mappings
When using tooltip, imports correctly use path mappings in ts-config (i.e. @location/component/etc). When the same class/object/whatever is imported during auto ...
Read more >
Auto Import Relative Path - Visual Studio Marketplace
Auto import relative path without typing long and tedious import statements and file paths. This extension is an alternative solution of dragΒ ...
Read more >
Documentation - Module Resolution - TypeScript
Finally, if the compiler could not resolve the module, it will log an error. ... Use non-relative paths when importing any of your...
Read more >
Getting VSCode Auto Import To Work With React - Medium
Also, if your compiler get's caught up on an error about not being able to resolve a path after an Auto Import, make...
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