You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

create-react-app设置max_old_space_size无效,触发语法错误

Fixing JS Heap Out of Memory + Syntax Error with create-react-app (v1.1.4)

Hey there, let's get this sorted out! The issue you're hitting happens because react-scripts v1.x doesn't recognize the --max_old_space_size parameter when you append it directly to the start/build commands—it tries to parse it as a react-scripts flag, which causes the syntax error. Here's how to fix it properly for your setup:

1. Directly Target the React Scripts Entry Files

Instead of passing the flag to react-scripts start, run the underlying Node script directly with the memory flag. Update your package.json scripts like this:

"scripts": {
  "start": "node --max_old_space_size=4096 node_modules/react-scripts/scripts/start.js",
  "build": "node --max_old_space_size=4096 node_modules/react-scripts/scripts/build.js"
}

This way, the memory flag is passed directly to Node, not to react-scripts, so it won't trigger a syntax error.

2. Use Environment Variables (Windows-Specific)

If you prefer not to modify the script paths, set the NODE_OPTIONS environment variable before running the command:

  • For Command Prompt:
    set NODE_OPTIONS=--max_old_space_size=4096 && yarn start
    
  • For PowerShell:
    $env:NODE_OPTIONS="--max_old_space_size=4096"; yarn start
    

You can also embed this directly in your package.json scripts (Windows-only):

"scripts": {
  "start": "set NODE_OPTIONS=--max_old_space_size=4096 && react-scripts start",
  "build": "set NODE_OPTIONS=--max_old_space_size=4096 && react-scripts build"
}

3. Clean Up Caches (Just to Be Safe)

Since you already reinstalled node_modules, let's make sure no stale cache is causing issues:

yarn cache clean
yarn install

Why Your Original Approach Failed

React-scripts v1.1.4 doesn't forward arbitrary Node flags to the underlying Node process when you append them to react-scripts start/build. It only accepts its own supported flags (like --verbose or --no-open), so passing --max_old_space_size confuses it and throws a syntax error.

内容的提问来源于stack exchange,提问作者bytecode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:54:27