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

tsconfig baseURL being used to resolve relative paths #3307

Closed
BenGladman opened this issue Aug 11, 2023 · 4 comments
Closed

tsconfig baseURL being used to resolve relative paths #3307

BenGladman opened this issue Aug 11, 2023 · 4 comments
Labels

Comments

@BenGladman
Copy link

BenGladman commented Aug 11, 2023

This is a recent regression (running esbuild 19)

Minimal reproduction case: https://github.com/BenGladman/esbuild-baseurl-issue

In the reproduction I'm importing from ../hello, and this should pick up the hello.ts file in the module's parent directory. But when bundling with esbuild, it is in fact importing hello.json, which is the file relative to the baseURL.

tsc does not do this. And according to the docs, baseURL should only be used to resolve non-relative imports.

@pfumagalli
Copy link

Seconded, I'm also seeing the same behavior. In the simplest case I could find I have:

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./subdir"
  }
}

test.ts

export const foo = "well, this is correct...";

subdir/test.ts

export const foo = "WRONG";

When running with 0.19.0:

$ esbuild --version
0.19.0
$ esbuild test.ts 
export const foo = "WRONG";
$

When running with 0.18.20

$ esbuild --version
0.18.20
$ esbuild test.ts 
export const foo = "well, this is correct...";
$

When running with the standard tsc:

$ tsc --version
Version 5.1.6
$ tsc --target esnext
$ cat ./test.js
export const foo = "well, this is correct...";
$

pfumagalli added a commit to plugjs/plug that referenced this issue Aug 11, 2023
@BenGladman
Copy link
Author

BenGladman commented Aug 11, 2023

Simplest fix for me is to remove the baseURL from tsconfig, which is a bit of a relic anyway. But that mightn't be possible for everyone

@pfumagalli
Copy link

Oh! @BenGladman you're right... I am using baseUrl because in a monorepo my tsconfig.json I had a paths statement looking like:

{
  "baseUrl": "./",
  "paths": {
    "otherpackage": [ "workspaces/otherpackage/src" ],
    "otherpackage/*": [ "workspaces/otherpackage/src/*" ]
  }
}

Removing it makes both tsc and esbuild complain (they say workspaces/... is not relative even if it actually is) but replacing the whole thing with:

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

and basically prefixing every path definition with ./ makes it go away and everything works like a charm!

Thanks!

pfumagalli added a commit to plugjs/plug that referenced this issue Aug 11, 2023
@evanw
Copy link
Owner

evanw commented Aug 11, 2023

Thanks for the report. I suspect this broke when I attempted to fix #3238 (moving tsconfig.json checks before --package=external checks). Unfortunately I don't currently have test coverage for this edge case.

@evanw evanw added the tsconfig label Aug 11, 2023
@evanw evanw closed this as completed in 1fca4aa Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants