Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Shperung opened this issue Sep 16, 2024 · 2 comments

Comments

@Shperung
Copy link

Shperung commented Sep 16, 2024

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);
@efstathiosntonas
Copy link

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.

@Shperung
Copy link
Author

Shperung commented Sep 20, 2024

Thank you. It's work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants