Skip to content

Reached heap limit Allocation failed - JavaScript heap out of memory "react-native": "0.75.3" #1355

Closed

Description

@Shperung

Maybe it's bug. But I'm not sure.

I have updated my ReactNavite from "react-native": "0.72.12", to "react-native": "0.75.3".

On version 0.75.3 I use dynamic imports modules and use React lazy/suspense components. If I load ~ more than 10 dynamic imports, I see long loading each imports and than
<--- JS stacktrace ---> FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory.

Same case was working good on "react-native": "0.72.12".

node v20.8.0

My relative dependencies

//...
    "react": "18.3.1",
    "@react-native/babel-preset": "0.75.3",
    "@react-native/eslint-config": "0.75.3",
    "@react-native/metro-config": "0.75.3",
    "@react-native/typescript-config": "0.75.3",
    "babel-preset-react-native": "4.0.1",
    "react-native-svg-transformer": "1.3.0",
    "react-native": "0.75.3",
//...

My metro.config.js

const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');

const defaultConfig = getDefaultConfig(__dirname);
const { assetExts, sourceExts } = defaultConfig.resolver;

const config = {
  transformer: {
    enableBabelRCLookup: false,
    babelTransformerPath: require.resolve('react-native-svg-transformer'),
  },
  resolver: {
    assetExts: assetExts.filter(ext => ext !== 'svg'),
    sourceExts: [...sourceExts, 'svg', 'mjs'],
  },
};

module.exports = mergeConfig(defaultConfig, config);

Activity

  1. efstathiosntonas commented on Sep 18, 2024

    @efstathiosntonas

    Try running with:

    node --max_old_space_size=16000 node_modules/react-native/cli.js start --reset-cache" for react native >= 0.75.x

    node --max_old_space_size=16000 node_modules/react-native/local-cli/cli.js start --reset-cache for react-native < 0.75.x

    Adjust 16000 based on your machine RAM, it's up to you if you want to keep the --reset-cache or not.

  2. Shperung commented on Sep 20, 2024

    @Shperung
    Author

    Thank you. It's work for me

  3. robhogan commented on Sep 3, 2026

    @robhogan
    Collaborator

    Apologies this didn't get a response.

    Same as #1191 - lazy bundling means parallel requests and multiple graphs, which compounds Metro's memory use rather than being a problem with dynamic imports as such. Raising the heap limit works around it, as you found.

    Metro's memory use and startup speed have both improved substantially since, though there's still more we plan to do to share memory between overlapping graphs, which is what lazy bundling leads to.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions