-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
paths
not used for auto import
#31173
Comments
I have the issue described below when using auto import in a project configured with Using vscode 1.34 on windows with provided tsserver I'm using webpack resolve: {
modules: [path.resolve(__dirname, './src/common'), 'node_modules'],
} To match same behavior in vscode, i configure jsconfig.json {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"*",
"./src/common/*"
]
}
}
} See sample project: https://github.com/blikblum/vscode-autoimport-path When i try to import from src/modules/main.js i get always relative to baseUrl which is clearly wrong: import { myService } from "src/common/myservice";
import { otherService } from "src/common/other/otherservice";
import { Home } from "src/home/home"; If i remove "*" from paths (see this branch) things are a little better: import { myService } from "myservice";
import { otherService } from "other/otherservice";
import { Home } from "src/home/home"; BTW this is the expected import: import { myService } from "myservice";
import { otherService } from "other/otherservice";
import { Home } from "../home/home"; In this branch, i try to use an empty jsconfig.json and get a technically correct import although not useful to achieve the intended behavior. |
I got a same issue |
I faced the same issue in my sample project. I guess this is the bug of compiler/moduleSpecifiers.ts#L260. The second argument of |
I got the same issue. Based on this stackoverflow post it is the same for both tsconfig.json and jsconfig.json. Sadly this makes VS Code unusable for our project, baseUrl workaround is not possible since we have more paths and imports inserted by VS Code are not working in the running app. |
In my case just by using in my settings "typescript.preferences.importModuleSpecifier": "non-relative", and then setting in my tsconfig {
"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. |
@nautilor - thank you for the tip. I have adjusted my workspace settings and on first glance it seems to be working! If this is solid, then it will be a huge timesaver. Thank you! |
@paustint |
I found there are some downsides for this approach in some cases. I am here -> The import resolves as this: When it should be: But the auto-imports from a relative |
That's because |
From microsoft/vscode#72931
TypeScript Version: 3.5.0-dev.20190430
Search Terms:
Repo
"typescript.preferences.importModuleSpecifier": "non-relative"
src/app/app1/test.ts
TestType
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:Actual behavior:
The import is added as
import { TestType } from "@myLib/example_2/_index";
The text was updated successfully, but these errors were encountered: