-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 & baseUrl is not supported in typescript? #16088
Comments
see #5039 (comment) |
Also see #14651 (comment) |
And #15479 |
This is a horrible thing to document on the documentation my expectations were that tsc will transform the module identifiers to proper path names. Whats the use case of this then? There seems to be no way of getting rid of relative path names. Is it really hard to get at least a basic plugin support feature so i can implemenr my own without hacking anything there. I am following the typescript development since the first versions... and this is the ONLY thing that got me off doing anything in typescript. And its been years now.. babel has plugin support and currently i really would like to use typings in a project to avoid common errors but this is just quite frustrating. |
if you are using a module loader with path configuration like SystemJs or require.
that is how ES6 modules are. there are no loaders for ES6, and there is no path mapping.
you can use TS to emit to |
Thanks thats a hacky way still but hopefully manageable. Much appreciated. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Just lol. |
As far addressing the issue I've ended up with my own post build script. It acutally uses the tsconfig.json paths and baseUrl setup. Hopefully it helps others who run into this issue. |
So do I understand correctly that there is no functionality in TypeScript to help with avoid relative paths in module imports? For example, Webpack has an alias where you can set This stackoverflow answer seems to suggest this is possible? |
@prograhammer correct, at the moment TypeScript resolves the aliases during the compilation process, but doesn't change the aliases in the final/generated code. That's why for example I build everything using Webpack for now, it's simpler for me than adding some scripts just to handle the aliases rewriting issue. |
Ah ok, just run it through Webpack (via |
I prefer |
@vladima @prograhammer Use https://github.com/mazhlekov/tsc-resolve but it only resolve |
If you use ts-node, the tsconfig-paths package may help. The transformation can also be done via babel with babel-plugin-module-resolver or webpack with tsconfig-paths-webpack-plugin. |
This simply doesn't make sense. I'm being suggested to include Babel for doing something that TypeScript could do, after all, doesn't TypeScript replace its functionality entirely? Why do I need to have two compilers for resolving a single problem? That's just lol as @azarus said. If TypeScript doesn't support this, then the entire compiler itself could be just a Babel plugin. |
Soo according to the documentation here:
https://www.typescriptlang.org/docs/handbook/module-resolution.html
And this proposal here:
#5039
I've tried to set up a simple typescript project using the paths and baseUrl path mapping to create shortcuts to folders.
Everything seemed fine in vscode but when i executed tsc from the commandline i found out its not working properly.
TypeScript Version:
Version 2.3.3
Code
tsconfig.json
Currently the following code is not resolved in tsc, and only resolved in vs code.
import { Test } from "@Core/Test"
This outputs an error that @Core/Test module is not found
Expected behavior:
It should resolve to:
import { Test } from "../../Test"
Actual behavior:
It stays the same in the output file, and is not resolved.
import { Test } from "@Core/Test"
The text was updated successfully, but these errors were encountered: