-
Notifications
You must be signed in to change notification settings - Fork 1.2k
dynamic import with vars help #2221
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
Comments
Dynamic import/require calls cannot be statically analysed, so esbuild cannot find corresponding files to bundle them. You can instead manually write them down: const Icons = {
name1: () => import('./icons/name1'),
};
export const getIcon = (name: IconTypes) => {
return lazy(Icons[name]);
}; |
@hyrious Yeah problem with that is there is like 300 icons so not really a good thing to do. i did fix it by doing this const getEntryPoint = () => new Promise<Array<string>>((resolve) => {
glob("./src/**/*.ts*x").then(res => resolve(res.filter(filename => !filename.includes("__"))));
})
return {
splitting: true,
tsconfig: paths.tsconfigJson, // default
entryPoints: await getEntryPoint(),
outdir: 'dist',
format: "esm",
minify: shouldMinify,
} problem is now my .d.ts file arent generating for some reason. |
Run-time file system emulation like this is out of scope, which is documented here: https://esbuild.github.io/api/#non-analyzable-imports. Closing this issue as out of scope. |
Hi There, loving the speed of esbuild but im having an issue with my dynamic import that has variables in it.
so the icons folder never gets generated in my repo so this fails, which breaks the icon component completely.
Is there any way to get this to import correctly.
The text was updated successfully, but these errors were encountered: