npm build gives “Ineffective mark-compacts near heap limit Allocation failed”

前端 未结 7 1129
萌比男神i
萌比男神i 2021-02-05 08:44

I have a reactjs/typescript project, running on windows 10. Im trying to build by ts-scripts with

\"rimraf ../wwwroot/* && react-scripts-ts build

7条回答
  •  失恋的感觉
    2021-02-05 08:55

    The root cause of the problem is the large source file sizes.

    You can resolve the issue in 2 steps.

    1. First try to increase space size and check the application. If the problem is cause by your source code, then this can be resolved by increasing the Node Heap Size as below,
    "start": "react-scripts --max_old_space_size=4096 start",
    "build": "react-scripts --max_old_space_size=4096 build"
    
    1. Second step is setting the Environment Variable. If the problem lies within your dependencies, you may need to increase the Node Heap allocation globally to resolve the issue.
      For Windows: set NODE_OPTIONS=--max_old_space_size=4096
      For Linux: export NODE_OPTIONS=--max_old_space_size=4096

    Also note that, if you are using very low memory like 512MB, then you will have to upgrade it to at least 2GB to get the better result.

    Here I used 4096MB = 4GB size, but you can change this according to your machine configuration specifically RAM. You can set it to 2GB or 1GB and check the application.

提交回复
热议问题