-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
spack: jsc.paths
are not relative to jsc.baseUrl
#2725
Comments
Does this issue is solved now ? |
It looks to me like it works as expected in |
You can pass absolute path if you are using js |
this doesnt work on windows, it always add "./' before the path and didnt normalize the path |
This stopped working for me recently. I'm not sure what changed. It should work just like TypeScript.
When I use See also: #1388 The workaround suggested to use absolute paths, but this is such a perf killer, as I have to generated a new config for every project in my monorepo, and have to search upwards for the project root for every single file. |
@vjpr which OS you are using? I'm using mac os and it works fine I think I experience this issue on windows machine |
Note that DOS path |
I also just got hit by this bug but it's not related to spack. The |
Hi @evanw @alfaproject, looks like it has been fixed on #8662. Could you check if it is resolved? P.S. The |
Sorry, I ended up using rspack for what I wanted to do and no longer have that problematic piece of code ): |
Describe the bug
I just tried using
jsc.paths
andjsc.baseUrl
now that #1943, #2050, #2126, and #2523 have been closed by #2712 and a new release has been published. But it still doesn't appear to be working. Here's a reduced test case:index.ts
:foo/foo.ts
:bar/bar.ts
:tsconfig.json
:spack.config.js
:Input code
No response
Config
No response
Playground link
No response
Expected behavior
The example code compiles fine with
tsc
:So I expect it to also work with
spack
. But the example code fails to be bundled by spack:It looks like spack is not treating
paths
as being relative tobaseUrl
. If I changespack.config.js
to use a path starting with../
then it succeeds, presumably because../bar/bar.ts
relative to./foo/foo.ts
is./foo/../bar/bar.ts
which gives you./bar/bar.ts
:However, that behavior differs from how
tsconfig.json
behaves. The documentation for spack indicates thatjsc.paths
is supposed to behave liketsconfig.json
: https://swc.rs/docs/configuration/compilation#jscpaths. So I assume this means it's a bug in spack. The paths in the config file should be relative tobaseUrl
, not to the directory containing the importing file.Version
@swc/cli: 0.1.51, @swc/core: 1.2.108
Additional context
Using
../
instead of./
as described above is not a valid workaround because the bug is that the path alias is being evaluated relative to the containing directory, which means that for large projects there will be no one relative path alias that works with all potential directories that code might import the path from.One workaround that I discovered which did work is to use absolute paths instead:
That could help avoid this issue until it's fixed.
The text was updated successfully, but these errors were encountered: