phosphor-icons / react

A flexible icon family for React
https://phosphoricons.com
MIT License
1.14k stars 60 forks source link

React web pack build error in phosphor icons #99

Closed nitish-javis closed 4 months ago

nitish-javis commented 5 months ago

WhatsApp Image 2024-06-11 at 3 31 58 PM

I'm facing this bug while doing npm run build. Tried to debug but couldn't find anything useful. But when I removed the phosphor icon library, then build worked fine.

OS: Mac Browser: Chrome

If anyone could help me here, it would be a great help. Thanks

rektdeckard commented 5 months ago

This is a pretty classic out-of-memory error that unfortunately happens because your build process is probably trying to load thousands of icons into memory while bundling, which is usually not necessary.

You can fix this a few ways:

  1. Use full import paths for each icon, so that the bundler only loads what you use:
    // this
    import { Check } from "@phosphor-icons/react/dist/csr/Check";
    import { Smiley } from "@phosphor-icons/react/dist/csr/Smiley";
    // instead of this
    import { Check, Smiley } from "@phosphor-icons/react";
  2. Increase the memory limit of the Node process. By default, I believe, Node only allocates 1024MB per process, and this error occurs when it tries to allocate something new and doesn't find enough memory remaining. You can give it more memory by changing the max-old-space-size option by setting an environment variable before calling your command:
    export NODE_OPTIONS="--max-old-space-size=4096"
    npm run build

    You can also just add it to the script in package.json:

    {
    "scripts": {
    "build": "NODE_OPTIONS='--max-old-space-size=4096' vite build"
    }
    }

Obviously the rest of your build command will differ based on the tools you're using, but it should work with everything. You can play around with the number, but 4GB should be plenty.

ChiragDugar02 commented 5 months ago

Hi @rektdeckard ,

We changed the imports according to your suggestion and we also tried running the server by increasing the node memory allocated. It still doesn't work. However, this time it throws some other error.

Screenshot 2024-06-12 at 12 52 06 PM
rektdeckard commented 5 months ago

That error is entirely different, and looks to be webpack exceeding the maximum string length in Node, which depending on your version of Node could be as low as ~260MB. I am not here to debug your application, but it sounds like you have some problems in your build setup.

Try upgrading Node (and webpack) if you're on an old version, look for anything that is concatenating into a massive string, and maybe try doing some debugging yourself.

rektdeckard commented 4 months ago

BTW it looks like you are using Node 15, which reached End Of Life like 2 years ago. Upgrading may resolve the problem, as memory allocation has undoubtedly improved in 9 major versions of Node.

rektdeckard commented 4 months ago

Closing as out-of-scope. This is simply too old a runtime for us to support.