You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vite/Rollup/ESBuild cannot process the dynamic imports in EuiIcon #5463
Here the module paths is constructed by string concatation to satisfy webpack. But vite/rollup has an opposite limitation that module paths must be constructed with template strings, otherwise there'll be a such error:
Edit: seems that I misread the rollup document, but the limitation causes this problem is the module paths do not contain a file extension. It has nothing to do with template strings.
3:12:25 AM [vite] warning:
/var/www/html/node_modules/.vite/@elastic_eui.js
47876| return;
47877| }
47878| import(
| ^
47879| /* webpackChunkName: "icon.[request]" */
47880| // It's important that we don't use a template string here, it
The above dynamic import cannot be analyzed by vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.
This results in many 404 errors in the application if it uses icons.
Reacted by James Gentes, Clifton Eaton, wadi, jx2011, sawadyecma, Christopher Chiche, Jon Marsh, Toni Tertsonen, Beomyeong Kim, SSE World and 5 more
Thanks for finding this @balthild! For context, I removed the concatenated .js extension in #5212 because local dev now uses Typescript / .tsx but production still compiles to .js, and Webpack was smart enough to find either the .tsx or .js version of it. I definitely didn't think of other bundlers like Rollup 🤦♀️
I think an easy/okay solution could be detect whether we're in dev vs prod and output .tsx vs .js with that in some kind of ternary. So on line 632, something like
No idea if EUI is setting NODE_ENV however or how that would actually work in a consumer environment, so someone should definitely double check that or find a condition that works 🙈
I'm not sure if vite could recognize a conditional string now, but I've find that I'm running into another problem that prevents us to confirm this - vite does not transpile the dynamic imports in a dependency module at all (vitejs/vite#6179). This is why the workaround I'd posted above adds a long typeToModuleMap object rather than simply adds .js file extension to the import expression. I think this issue is therefore not possible to fix before vitejs/vite#6179 is fixed.
Vite user here. Using the appendIconComponentCache() method works well enough when I'm creating my own components.
The DX falls down when adding components with many different icons (such as EuiInMemoryTable) because I have to search the source code.
It would be nice to have a list of icons the component uses in the docs.
Hi @henry-young,
I use Vite too and have run into a similar problem. How did you get the appendIconComponentCache function to work? Could you give an example of its use in Vite?
Hi @henry-young, I use Vite too and have run into a similar problem. How did you get the appendIconComponentCache function to work? Could you give an example of its use in Vite?
and then I just have a file named ~/src/icons.ts that contains.
import { ICON_TYPES } from '@elastic/eui';
import { ValuesType } from 'utility-types';
import { appendIconComponentCache } from '@elastic/eui/es/components/icon/icon';
import { icon as magnifyWithMinus } from '@elastic/eui/es/components/icon/assets/magnifyWithMinus';
import { icon as minus } from '@elastic/eui/es/components/icon/assets/minus';
import { icon as magnifyWithPlus } from '@elastic/eui/es/components/icon/assets/magnifyWithPlus';
import { icon as plus } from '@elastic/eui/es/components/icon/assets/plus';
type IconComponentNameType = ValuesType<typeof ICON_TYPES>;
type IconComponentCacheType = Partial<Record<IconComponentNameType, unknown>>;
const cachedIcons: IconComponentCacheType = {
magnifyWithMinus,
magnifyWithPlus,
minus,
plus,
...
};
appendIconComponentCache(cachedIcons);
And then a global.d.ts file containing a basic module definition for the icons (so typescript doesn't complain)
Hi @henry-young, I use Vite too and have run into a similar problem. How did you get the appendIconComponentCache function to work? Could you give an example of its use in Vite?
and then I just have a file named ~/src/icons.ts that contains.
import { ICON_TYPES } from '@elastic/eui';
import { ValuesType } from 'utility-types';
import { appendIconComponentCache } from '@elastic/eui/es/components/icon/icon';
import { icon as magnifyWithMinus } from '@elastic/eui/es/components/icon/assets/magnifyWithMinus';
import { icon as minus } from '@elastic/eui/es/components/icon/assets/minus';
import { icon as magnifyWithPlus } from '@elastic/eui/es/components/icon/assets/magnifyWithPlus';
import { icon as plus } from '@elastic/eui/es/components/icon/assets/plus';
type IconComponentNameType = ValuesType<typeof ICON_TYPES>;
type IconComponentCacheType = Partial<Record<IconComponentNameType, unknown>>;
const cachedIcons: IconComponentCacheType = {
magnifyWithMinus,
magnifyWithPlus,
minus,
plus,
...
};
appendIconComponentCache(cachedIcons);
And then a global.d.ts file containing a basic module definition for the icons (so typescript doesn't complain)
@constancecchen , I think he thought, for example, that the API pages of table components like EuiTable doesn't have the names of the icons used by the component, so it's hard to know what icons we want to cache. The same is true for other components that use built-in icons.
Ah, you're totally right, I missed that context, apologies! We're not likely to update our docs to include a list of all icons each component uses as SSR consumers are still an edge case for us (and for the original issue, the file extension issue can be addressed either by Vite or EUI) - but as Henry did it's possible for consumers to grep through our source code for components looking for either EuiIcon or iconType.
We had a brief sync about this today, and we'd be open to changing the import method.
One difficulty I see with the referenced path is that we have 4 different builds (es, lib, optimize/es, and optimize/lib) and the import path would need to change for each:
Right now each build, as well as local dev (with webpack dev server), work because of the relative './assets/' pathing in the concatenated string. We'd need to alter the import at build time to accommodate each build but keep local imports working for dev environments.
Reacted by Cee Chen, Chandler Prall, Danny Allen and Christopher Chiche
We've migrated to vite as a result of moving to dotnet 9, which is now using vite for its default client templates.
The approach with copying all icon imports into a file, or including the ones used in code + where part of any built-in components, is definetely not ideal.
Also, with the workaround of including all icons imports and adding to cache, can somebody comment on impact on both dev and prod bundle size?
👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.
With Astro, Next.js, and Vite rapidly becoming the modern web stack, native support for these frameworks should be a top priority for EUI to stay relevant and competitive.
Reacted by Razvan Margineanu, Tom, David Fernandez and exe
Activity
balthild commentedon Dec 12, 2021
A workaround, using
patch-package:Click to expand
./patches/@elastic+eui+43.0.0.patchcee-chen commentedon Dec 14, 2021
Thanks for finding this @balthild! For context, I removed the concatenated
.jsextension in #5212 because local dev now uses Typescript /.tsxbut production still compiles to.js, and Webpack was smart enough to find either the.tsxor.jsversion of it. I definitely didn't think of other bundlers like Rollup 🤦♀️I think an easy/okay solution could be detect whether we're in dev vs prod and output
.tsxvs.jswith that in some kind of ternary. So on line 632, something likeNo idea if EUI is setting NODE_ENV however or how that would actually work in a consumer environment, so someone should definitely double check that or find a condition that works 🙈
balthild commentedon Dec 19, 2021
I'm not sure if vite could recognize a conditional string now, but I've find that I'm running into another problem that prevents us to confirm this - vite does not transpile the dynamic imports in a dependency module at all (vitejs/vite#6179). This is why the workaround I'd posted above adds a long
typeToModuleMapobject rather than simply adds.jsfile extension to the import expression. I think this issue is therefore not possible to fix before vitejs/vite#6179 is fixed.cee-chen commentedon Dec 20, 2021
Ahhh, gotcha. Another alternative for consuming
EuiIcons is how SSRs handle it: https://github.com/elastic/eui/tree/main/wiki/consuming-eui#failing-icon-importshenry-young commentedon Apr 22, 2022
Vite user here. Using the
appendIconComponentCache()method works well enough when I'm creating my own components.The DX falls down when adding components with many different icons (such as
EuiInMemoryTable) because I have to search the source code.It would be nice to have a list of icons the component uses in the docs.
TomSoldier commentedon Apr 22, 2022
Hi @henry-young,
I use Vite too and have run into a similar problem. How did you get the appendIconComponentCache function to work? Could you give an example of its use in Vite?
henry-young commentedon Apr 23, 2022
Firstly in
vite.config.jsI addedand then I just have a file named
~/src/icons.tsthat contains.And then a
global.d.tsfile containing a basic module definition for the icons (so typescript doesn't complain)I hope that helps.
TomSoldier commentedon Apr 23, 2022
Thank you, I understand how it works now. I missed the module declaration.
cee-chen commentedon Apr 25, 2022
Thanks for posting that super detailed comment @henry-young!
Maybe I'm missing something, but you definitely shouldn't have to search our source code to look at a list of all our icons - they should be available for preview/search at https://elastic.github.io/eui/#/display/icons#glyphs (you can click the icon to copy the
iconType). Hope that helps!TomSoldier commentedon Apr 25, 2022
@constancecchen , I think he thought, for example, that the API pages of table components like EuiTable doesn't have the names of the icons used by the component, so it's hard to know what icons we want to cache. The same is true for other components that use built-in icons.
cee-chen commentedon Apr 25, 2022
Ah, you're totally right, I missed that context, apologies! We're not likely to update our docs to include a list of all icons each component uses as SSR consumers are still an edge case for us (and for the original issue, the file extension issue can be addressed either by Vite or EUI) - but as Henry did it's possible for consumers to grep through our source code for components looking for either
EuiIconoriconType.badwulfy commentedon Jul 12, 2022
I use Parcel bundler and I have the same issue.
As I don't like to add each icon by hand, I made a patch for the latest version of Elastic UI : https://gist.github.com/badwulfy/2a59c5ab8866439ff074e05e136b653d
thompsongl commentedon Jul 12, 2022
We had a brief sync about this today, and we'd be open to changing the import method.
One difficulty I see with the referenced path is that we have 4 different builds (
es,lib,optimize/es, andoptimize/lib) and the import path would need to change for each:accessibility: () => import('@elastic/eui/es/components/icon/assets/accessibility')Right now each build, as well as local dev (with webpack dev server), work because of the relative
'./assets/'pathing in the concatenated string. We'd need to alter the import at build time to accommodate each build but keep local imports working for dev environments.jgentes commentedon Aug 15, 2022
+1 for having a simpler solution, but nice to have a workaround. I'm using Vite.
13 remaining items
tstojecki commentedon Nov 29, 2024
We've migrated to vite as a result of moving to dotnet 9, which is now using vite for its default client templates.
The approach with copying all icon imports into a file, or including the ones used in code + where part of any built-in components, is definetely not ideal.
Also, with the workaround of including all icons imports and adding to cache, can somebody comment on impact on both dev and prod bundle size?
jwaltz commentedon Jan 18, 2025
Thanks so much for the icon generation tool.
Would anyone happen to know how I can handle the following error emitted by Vite using the
appendIconComponentCache(cachedIcons)approach?github-actions commentedon Aug 23, 2025
👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.
adhishthite commentedon Oct 11, 2025
bump
adhishthite commentedon Oct 11, 2025
With Astro, Next.js, and Vite rapidly becoming the modern web stack, native support for these frameworks should be a top priority for EUI to stay relevant and competitive.