I have a reactjs/typescript project, running on windows 10. Im trying to build by ts-scripts with
\"rimraf ../wwwroot/* && react-scripts-ts build
I don't think that the solution is to increase memory limit. This way the issue is always postponed.
I've encounter this issue 2 times. I've solved, for each time:
node
(v12.11.1
, react v16.13.1
and react-scripts v3.2.0
);npm
to yarn
(node v12.11.1
, react v16.13.1
and react-scripts v3.4.1
).In addition, check your package.json
, delete package-lock.json
, remove node-modules
folder and try to install your dependencies again.
Next try to build your project.
The solution which I used was to upgrade the node js version from v10 to v12.
The command export NODE_OPTIONS=--max_old_space_size=4096
works but has limitations, e.g. you should have ample memory on your machine to run the production build.
The root cause of the problem is the large source file sizes.
You can resolve the issue in 2 steps.
"start": "react-scripts --max_old_space_size=4096 start",
"build": "react-scripts --max_old_space_size=4096 build"
set NODE_OPTIONS=--max_old_space_size=4096
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.
I got a fix after increasing the node max_old_space. Here is the fix.
Instead of running npm start or ng start. Run the below command
node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve
OR
You can add the command in package.json
file as well
"start": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve"
I had the same issue on Windows. The solution was to set the NODE_OPTIONS variable before running npm run build. To set this variable, simply run set NODE_OPTIONS=--max_old_space_size=8192
I had a similar issue, although on a Mac computer. Setting an environment variable did the trick for me. That way, your node process will take the value and use it independently of which script you're running.
export NODE_OPTIONS=--max_old_space_size=4096
The run your command again. Good Luck!