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
Build fails when using a React component with react-icons within an astro file #7629
When using react-icons (4.10.1) within a React component that is referenced in an Astro file and the build script is run via npm run build the build fails with the following error:
generating static routes
error Named export 'BsGithub' not found. The requested module 'react-icons/bs/index.esm.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'react-icons/bs/index.esm.js';
const { BsGithub, BsLinkedin } = pkg;
Running the project using npm run dev works fine and the icons render as expected.
What's the expected result?
The app and all corresponding assets are built successfully as expected.
changed the title [-]build fails when using a react component with react-icons within an astro file [/-][+]Build fails when using a react component with react-icons within an astro file [/+]on Jul 12, 2023
changed the title [-]Build fails when using a react component with react-icons within an astro file [/-][+]Build fails when using a React component with react-icons within an astro file [/+]on Jul 12, 2023
This vite issue might also be helpful context with some possible solutions. Astro is able to update vite configuration directly by modifying the vite object in your astro.config.mjs file. See this recipe for more context.
I'm not sure this is an Astro issue; the problem is clearly the package. @bluwy do you know if there's a way, via Astro config, to bypass the issue?
Sorry forgot to reply to this. A way would be to follow the syntax as suggested by the error message. Or another way is to configure ssr.noExternal: ['react-icons'] to bundle it to hide from being loaded by Node.js
Reacted by David, GrumpyEric, Alberto Hernandez, Medhat Dawoud and Bambang Mohammad Azhari
I'm not sure this is an Astro issue; the problem is clearly the package. @bluwy do you know if there's a way, via Astro config, to bypass the issue?
Sorry forgot to reply to this. A way would be to follow the syntax as suggested by the error message. Or another way is to configure ssr.noExternal: ['react-icons'] to bundle it to hide from being loaded by Node.js
Worked for me! The astro.config.mjs file ends up looking like this:
Reacted by Samin Yaser, Niroyan Kugaruban, Alberto Hernandez, nilswg, Suvan Leelasena, Bijoy Kar, Patrick Chiu, Matt Bowolick, Hector Araújo, 김광훈 and 8 more
Reacted by Manfred__
Reacted by bruno-py and AR. Arif
Reacted by nilswg, Miguel Jara and Rafael Bernardo
Reacted by Medhat Dawoud, AR. Arif and Rafael Bernardo
Activity
[-]build fails when using a react component with react-icons within an astro file [/-][+]Build fails when using a react component with react-icons within an astro file [/+][-]Build fails when using a react component with react-icons within an astro file [/-][+]Build fails when using a React component with react-icons within an astro file [/+]ematipico commentedon Jul 12, 2023
The
react-iconsincorrectly export their packages: https://publint.dev/[email protected]I'm not sure this is an Astro issue; the problem is clearly the package. @bluwy do you know if there's a way, via Astro config, to bypass the issue?
natemoo-re commentedon Jul 18, 2023
Closing this issue since it's upstream. Unfortunately, we can't make every outdated package work with Astro out of the box.
react-iconsissue.viteissue might also be helpful context with some possible solutions. Astro is able to updateviteconfiguration directly by modifying theviteobject in yourastro.config.mjsfile. See this recipe for more context.bluwy commentedon Jul 19, 2023
Sorry forgot to reply to this. A way would be to follow the syntax as suggested by the error message. Or another way is to configure
ssr.noExternal: ['react-icons']to bundle it to hide from being loaded by Node.jsbuckldav commentedon Aug 16, 2023
Worked for me! The
astro.config.mjsfile ends up looking like this:yanniro2 commentedon Sep 29, 2023
its working. thank you 🤩
Changed astro config to try to fix react-icons issue