_From @methyl on July 12, 2016 14:45_
Currently Go To Definition works perfectly well for relative paths within application, eg:
import something from './something'
However, after I add some resolve paths in Webpack config, like
resolve: {
root: [
path.resolve(rootPath, 'app/frontend/lib'),
I can import files like this
import something from 'something'
// instead of
// import something from 'app/frontend/lib/something' or
// import something from '../../lib/something'
The problem is that VSCode won't follow these resolve paths.
The solution could be to add configuration which will define additional resolve paths for Go To Definition functionality.
_Copied from original issue: Microsoft/vscode#9135_
Might be solveable with the new baseURL support in TS 2.0. Moving to TS team.
+1 for this
Webstorm handles webpack resolve.root pretty seamlessly (though I have no idea how that works under the hood, or indeed if VS Code's guts are even remotely similar)
as noted by @dbaeumer this should be handled with the new baseUrl property in your config file, see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md#base-url
so in your jsconfig.json add:
{
"compilerOptions": {
....
"baseUrl": "app/frontend/lib"
}
}
I should add, this is fixed in the next release (TS 2.0) or using the nightly (see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Nightly%20Builds.md)
copied from https://github.com/Microsoft/vscode/issues/9135#issuecomment-266945304
Hello, @dbaeumer !
this feature seems not working for me.
i checked my vscode version, (1.7.2) which uses typescript server 2.0.10
and i also tried to use typescript@next for my vscode,
but vscode hint me with underline as Property baseUrl is not allowed.
so i changed jsconfig.json => tsconfig.json,
then add allowJs true at compilerOptions, but still not working.
is there anything else that i'm missing?
(p.s. I really enjoy coding with vscode. Thank you! * 10000)
@olafahn Can you please file a separate issue while following guidelines? This makes it easier for us to manage the issue tracker. Thanks!
What if the alias setup is more complex than a simple baseUrl? Is there a way to declare aliases like in Webpack?
What if the alias setup is more complex than a simple baseUrl? Is there a way to declare aliases like in Webpack?
You can also use Path mapping
For the Googlers who don't want to follow the many links: I made a writeup on how to accomplish this. TL;DR add
{
"compilerOptions": {
// This must be specified if "paths" is set
"baseUrl": ".",
// Relative to "baseUrl"
"paths": {
"*": [
"*",
"mypath/*"
]
}
}
}
to your jsconfig.json or tsconfig.json in your project's root.
Most helpful comment
as noted by @dbaeumer this should be handled with the new
baseUrlproperty in your config file, see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md#base-urlso in your jsconfig.json add: