How to fix “FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory” error

前端 未结 6 501
再見小時候
再見小時候 2020-12-15 17:52

I\'m trying to deploy a reactjs application to heroku. While compiling assets, the build fails and produces this error:

-----> Ruby app detected
----->         


        
相关标签:
6条回答
  • 2020-12-15 18:32

    I had a similar heap allocation error while deploying to Heroku. The app would still build correctly but would not load in the browser. Heroku logs would show me this: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

    After trying a dozen different things this seemed to work in package.json:

     "start": "react-scripts --max_old_space_size=4096 start",
     "build": "react-scripts --max_old_space_size=4096 build",
    
    0 讨论(0)
  • 2020-12-15 18:38

    In my case this error was caused by the fact that I imported twice the same less files:

    @import "~@myPackage/file1.less";
    @import "~@myPackage/file1.less";
    
    @import "~@myPackage/file2.less";
    @import "~@myPackage/file2.less";
    
    0 讨论(0)
  • 2020-12-15 18:40

    The root cause of the issue is due to large source file sizes.
    If the underline problem is within your source code you can resolve it by simply 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",
    But if the problem lies within any dependencies introduced, we 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
    
    0 讨论(0)
  • 2020-12-15 18:42

    That problem is related with large files in your project.

    I'm using create-react-app, and I got that error, after doing some search, it seems one solution is this.

    Put in .env file:

    GENERATE_SOURCEMAP=false
    
    0 讨论(0)
  • 2020-12-15 18:44

    I had the same error. Fixed it by using an earlier version of Node/npm. Might fix your problem.

    0 讨论(0)
  • 2020-12-15 18:47

    its because more "js" files in your react Application. You can build your application after making some Changes in package.json like below of code:

    "scripts": {
            "start": "react-scripts --max_old_space_size=4096 start",
            "build": "react-scripts --max_old_space_size=4096 build",
            "test": "react-scripts test",
            "eject": "react-scripts eject"
          },
    
    0 讨论(0)
提交回复
热议问题