Skip to content
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

Build fails when using a React component with react-icons within an astro file #7629

Closed
1 task
kimwoodfield opened this issue Jul 12, 2023 · 5 comments
Closed
1 task
Labels
ecosystem: external External library doesn't work

Comments

@kimwoodfield
Copy link

kimwoodfield commented Jul 12, 2023

What version of astro are you using?

2.8.0

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Windows, Mac

What browser are you using?

Chrome

Describe the Bug

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.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-z3zm9g?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@kimwoodfield kimwoodfield 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 Jul 12, 2023
@kimwoodfield kimwoodfield 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 Jul 12, 2023
@ematipico
Copy link
Member

The react-icons incorrectly export their packages: https://publint.dev/react-icons@4.10.1

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?

@Princesseuh Princesseuh added the ecosystem: external External library doesn't work label Jul 17, 2023
@natemoo-re
Copy link
Member

Closing this issue since it's upstream. Unfortunately, we can't make every outdated package work with Astro out of the box.

  • Here's the upstream react-icons issue.
  • 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.

@natemoo-re natemoo-re closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
@bluwy
Copy link
Member

bluwy commented Jul 19, 2023

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

@buckldav
Copy link

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:

import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
  ...,
  vite: {
    ssr: {
      noExternal: ["react-icons"],
    },
  },
});

@yanniro2
Copy link

its working. thank you 🤩

allison-truhlar added a commit to JaneliaSciComp/ossi-website that referenced this issue Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem: external External library doesn't work
Projects
None yet
Development

No branches or pull requests

7 participants