Open Marshal27 opened 3 years ago
I ran into this today and the title should probably be "esbuild plugin does not follow TypeScript path aliases" as it's a more generic issue.
It's pretty common to use path aliases:
import something from '~/path/to/something';
// vs.
import something from '../../../something';
TypeScript supports this in tsconfig.json
, e.g.
{
"compilerOptions": {
"paths": {
"~/*": [
"src/*"
],
}
}
}
When used, esbuild will honor this syntax and things "just work." However, when used with WTR, the following error occurs:
Error while transforming [source file]: Could not resolve import "~/path/to/something".
It seems like WTR's esbuild plugin isn't aware of the tsconfig.json
, so having the ability to customize the config through the plugin API would be one way to mitigate this. Perhaps a more convenient solution would be to look for tsconfig
and automatically pass compilerOptions.paths
to esbuild.
@LarsDenBakker I'm not familiar with WTR's codebase. Do either of these sound like a reasonable option? Can you think of a better approach to make this work?
If you'd like a test repo, let me know and I'll set one up.
Any update on this issu?
I have an Open-WC generated typescript monorepo with Lerna on top; I am using the esbuild plugin for the dev server per the recommendation in the documentation.
I am struggling to import the side effect from an NPM package dev dependency using the esbuild plugin.
esbuild settings