-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
path-mapping will import module twice when use tsc #16283
Comments
This can be temporarily solved by Perhaps we can update the documentation to explain this unexpected behavior? |
@ohroy is this when using bun runtime with tsc (ie |
@RiskyMH Thanks for quick response "paths": {
"@/*": ["./src/*"]
} source.ts import xx from '@/xx' after tsc build dist.js import xx from '@/xx' tsc not care about alias, but bun care it! SO, when dist and src and alias both exist, what file will bun resolve ? The answer is BOTH Bun will import xx.ts when exec dist.js (by parse alias to @/src, there are ts files), and bun will also import xx.js when some file not import by alias. dist2.js import xx from './xx' Then, same xx, but different path, the same logic will be exec 2 times. |
This may be a marginal case, but it happens in a subtle and coincidental way that is not easily noticed. If anyone encounters the same strange problem, please use |
Oh I see the problem now thanks! What solution would you like Bun to do though? As node (not reading tsconfig.json) would just error out completely, and as Bun has no way of knowing that you didn't want path specified in tsconfig its a little hard. Edit: also good thing in Bun we don't need Overall, I think your |
Thanks! Maybe this is not a bug, but overall it may lead to undefined results, which I think is worth optimizing. In monorepo, compiling the library into js and publishing it to npm is a common scenario. I thought of 3 solutions,
This is just a starting point, maybe someone else has a better idea. |
guess what, you can use "bun" export condition already :) |
💯 amazing!!! great bun!!! I just tested, It solves the problem perfectly !!! Thanks! : ) |
What version of Bun is running?
1.1.43
What platform is your computer?
No response
What steps can reproduce the bug?
tsconfig
then, if you use tsc build to dist, the tsc NOT deal anything about paths, so if other package import this package, what will happen ?
it will import the the same module 2 times,
1 times for ts, and other for dist/js
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: