-
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
--packages=external does not work in conjunction with typescript path aliases #2792
Comments
That's just what the The |
I get that, but just like mentioned in the docs for esbuild alias:
Wouldn't it make sense to resolve typescript aliases before marking paths as imports? Otherwise, is it possible to write a plugin that also runs after the paths are resolved? |
Yes. The current API for this is not that elegant but you can use the |
Still I think this should be up for discussion:
But I'll close the ticket and if it never gains traction I guess it's just my personal need |
My intuition was also that the the externalisation of packages would happen after tsconfig paths/baseUrl are resolved. I agree this would be a good feature; an option (packages: external) that overrides the functionality of a built-in feature (tsconfig resolution) seems likely to violate expectations. Nonetheless, the advice above on creating a plugin was helpful, and this seems to work adequately: import { Plugin } from "esbuild";
export function externalModulesPlugin(): Plugin {
return {
name: "external-modules",
setup(build) {
build.onResolve({ filter: /.*$/ }, async (args) => {
if (!args.pluginData?.resolved) {
const resolveResult = await build.resolve(args.path, {
kind: "import-statement",
resolveDir: args.resolveDir,
pluginData: { resolved: true },
});
if (resolveResult.path.includes("/node_modules/")) {
return { path: args.path, external: true, sideEffects: false };
}
return resolveResult;
}
return undefined;
});
},
};
} |
@djgrant Thanks a lot for the solution 💝. I guess this issue should be addressed. |
tsConfig paths:
With
--packages=external
, esbuild results in files using the$lib
alias to compile to the following:Instead of bundling
$lib/something
which is a local file, not a file fromnode_modules
Here's the full command I'm using:
The text was updated successfully, but these errors were encountered: