Skip to content

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

Closed as not planned

Description

@kimwoodfield

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.

Activity

  1. 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
  2. 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
  3. ematipico commented on Jul 12, 2023

    @ematipico
    Member

    The react-icons incorrectly 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?

  4. added
    ecosystem: external
    on Jul 17, 2023
  5. natemoo-re commented on Jul 18, 2023

    @natemoo-re
    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.
  6. bluwy commented on Jul 19, 2023

    @bluwy
    Member

    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

  7. buckldav commented on Aug 16, 2023

    @buckldav

    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"],
        },
      },
    });
  8. yanniro2 commented on Sep 29, 2023

    @yanniro2

    its working. thank you 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecosystem: external

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions