-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Autoimport always imports relative to baseUrl #19920
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
Comments
From @martaver on November 9, 2017 20:17 Also seeing this behavior, in 1.18 and previous, on both manually chosen import fixes and the new auto-import on completion feature. |
From @martaver on November 9, 2017 20:34 For me, removing the baseUrl entry from my tsconfig.json file fixed the issue. |
@mjbvz would this issue also affect autoimport in JS/JSX? I'd have a few suggestions for the feature, but don't know if this is the correct place for it. |
@kumarharsh Yes, they're the same feature. |
OK, so I found the feature useful, although a little rough to use because the import paths it produces are not how the rest of the code is written. Many times, I export code from the import { A, B, C } from 'constants/Widgets';
If the vscode solution can take these into account, it'd be awesome. |
|
Oh, awesome! I think No. 2 is already working as expected (my mistake to point that out). About No. 3, my project is a JS project, so there's no tsconfig, but a jsconfig is there. |
you should be able to set the same options in |
@Andy-MS I am confused about rootDirs vs paths. I can only get non-relative imports to work using the paths setting. "paths": {
"*": ["*", "src/*"]
}, Setting And with the paths setting I still have the issue that I reported here Here's my full tsconfig: {
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["es6", "es7", "esnext", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noEmitOnError": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"outDir": "build/dist",
"paths": {
"*": ["*", "src/*"]
},
"plugins": [
{
"name": "tslint-language-service"
}
],
"rootDirs": [".", "src"],
"skipLibCheck": false,
"sourceMap": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es6"
},
"exclude": ["build", "config-overrides.js", "jest", "scripts"],
"include": ["src/**/*"]
} |
@mhegazy - the rootDirs setting is not working for me. |
paths is completely broken in my case |
#19724 should give multiple imports anyways.. this will address some of these requests.. |
You find more info about |
Is this fully fixed by #19724? |
@kumarharsh, @stevematdavies and @0x80 can you give #19724 a try? the fix should be in |
@mhegazy I did not notice any change in behavior so far. I'm trying to use I've tried this: "rootDirs": [
"src"
],
"baseUrl": "src",
"paths": {
"@src/*": [
"*"
],
"~/*": [
"*"
] And this: "baseUrl": ".",
"paths": {
"@src/*": [
"src/*"
],
"~/*": [
"src/*"
]
}, When I try to import the file from If I try to import something what has no name relation to one of my dependencies, the tab key simply inserts a tab space. So no auto-completion at all. |
Is it broken again? I remember 1-1.5 months ago VS code (using 1.19-insider version) had been displaying the picker with 2 choices: relative path and baseurl path. Now it's autoimporting only baseurl derived paths without any prompts. TS: 2.7.0-dev.20180119 |
@mhegazy Since 1.20 Visual Studio Code uses the shorter relative path. This is an issue for the project I'm working on since we stated we prefer using the full path, in order to ease refactoring. How to I tell VS Code to prefer the full path? I can't find documentation about this, and a first glance reading the code the behaviour might be hard-coded. |
@guillaumep we had the same issue and fixed it by adding the following in our
That makes the auto import set the import string to |
@mikfoo All my imports are from 'src', so this workaround would not work. |
@guillaumep Actually, we are using
|
@mikfoo I have changed my config from: "baseUrl": "./", "paths": { "src": ["./src"] } to: "baseUrl": "./", "paths": { "src/*": ["src/*"] } and VS Code now imports from |
@mjbvz Your solution worked for me as well |
Guys, sorry to write in the closed issues, but all my package imports are imported using relative paths ;( This is my tsconfig.json and typescript 2.9.2 "compilerOptions": {
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2017", "dom"],
"jsx": "react",
"noEmit": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"pretty": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": false,
"experimentalDecorators": true,
"typeRoots": ["src/shared/models", "node_modules/@types"]
} [EDIT] If need be I can create a new issue. |
@tomitrescak I believe it is related to #25279. What happens with |
@kitsonk yup, the issue is gone! thanks ... now I do not get the auto correct helper with "CMD + ." but I guess that will arrive later ;) |
From @artaommahe on November 9, 2017 11:38
Steps to Reproduce:
baseUrl
baseUrl
relative importexpected import relative to current file
Reproduces without extensions: Yes
Copied from original issue: microsoft/vscode#37928
The text was updated successfully, but these errors were encountered: