Skip to content
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

Typescript Path Alias supporting #379

Closed
jw-foss opened this issue Apr 29, 2019 · 13 comments · Fixed by #1834
Closed

Typescript Path Alias supporting #379

jw-foss opened this issue Apr 29, 2019 · 13 comments · Fixed by #1834
Assignees
Milestone

Comments

@jw-foss
Copy link

jw-foss commented Apr 29, 2019

Hi, I am trying to bring swc-loader into my daily job, based on the current working stack:
React with typescript, then I encountered a problem which is the path alias(resolving)
in tsconfig.json I mapped the paths like this:

{
...
"paths": {
   "@/*": ["src/*"]
},
...
}

when I changed the babel-loader to swc-loader, the path alias (resolving) seems not working anymore:

Module not found: Can't resolve '@/types.local' in `~/work/project/src/dux/actions';

I wonder that maybe, if swc compiler can read the configurations from the local tsconfig.json, and match the functionality?
Any help would be very much appreciated. Thanks.

@besok
Copy link
Contributor

besok commented Dec 30, 2020

hello, can i take on this issue?

@kdy1
Copy link
Member

kdy1 commented Dec 30, 2020

Of course, thank you in advance.

@besok
Copy link
Contributor

besok commented Jan 4, 2021

attached the documentation to the future.
https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

@wxs77577
Copy link

Thanks for your great project.I'm using nestjs monorepo https://docs.nestjs.com/cli/monorepo, it uses paths to define path aliases in tsconfig.json.Is there any progress or roadmap on implementation of this feature?

@kdy1 kdy1 modified the milestones: v2.0, v1.2.47 Jan 28, 2021
@kdy1
Copy link
Member

kdy1 commented Jan 28, 2021

@wxs77577 I'll implement this with a new minor version of swc. (Finally, I have an idea how to implement it correctly)

@kdy1
Copy link
Member

kdy1 commented Jan 30, 2021

@wxs77577 Do you use swc via swc-loader?

@wxs77577
Copy link

@wxs77577 Do you use swc via swc-loader?

I just use swc cli.

@kdy1 kdy1 modified the milestones: v1.2.47, v1.2.48 Jan 31, 2021
@kdy1 kdy1 modified the milestones: v1.2.48, v1.2.49, v1.2.50 Feb 19, 2021
@kdy1 kdy1 modified the milestones: v1.2.50, v1.2.51 Mar 3, 2021
@kdy1 kdy1 modified the milestones: v1.2.51, v1.2.52 Mar 28, 2021
@kdy1 kdy1 modified the milestones: v1.2.52, v1.2.53 Apr 8, 2021
@kdy1 kdy1 modified the milestones: v1.2.53, v1.2.54 Apr 16, 2021
@kdy1 kdy1 self-assigned this Apr 17, 2021
@kfirba
Copy link

kfirba commented May 31, 2021

@kdy1 I saw that you closed the associated PR. Any plans for implementing this?

@kdy1
Copy link
Member

kdy1 commented May 31, 2021

Yes, but I'm too busy these days.

@kdy1
Copy link
Member

kdy1 commented Jun 18, 2021

I started working on this, and I'm not sure if it's correct to support both of babel rewriter and tsconfig rewriter.
What do you guys think?

kdy1 added a commit that referenced this issue Jun 24, 2021
swc_ecma_loader:
 - Add `Resolve`. 
 - Add `TsConfigResolver`. 

swc_ecma_transforms_module:
 - Use `Resolve` for remapping import paths.
 - Add `ImportResolver`.
 - Add `NodeImprortResolver`.

swc:
 - Add `paths` to `.swcrc`.
 - Use `paths`. (#379, #702)
 - Canonicalize file names.
@ibraelillo
Copy link

This is still not working for es6. cjs works fine, it seems.

@kdy1
Copy link
Member

kdy1 commented Jan 13, 2022

Can you file a new issue?

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 19, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.