Reputation: 187
My code pipeline stopped working and the error message is:
yarn run v1.21.1
$ react-app-rewired build
Creating an optimized production build...
<--- Last few GCs --->
[23:0x55e3d7ad8700] 188895 ms: Mark-sweep 1824.5 (1875.9) -> 1823.0 (1883.6) MB, 1725.5 / 0.0 ms (average mu = 0.109, current mu = 0.013) allocation failure scavenge might not succeed
[23:0x55e3d7ad8700] 191161 ms: Mark-sweep 1831.3 (1884.2) -> 1829.9 (1889.8) MB, 2253.0 / 0.0 ms (average mu = 0.052, current mu = 0.006) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x55e3d5b70342]
Security context: 0x0be28ab9a299 <JSObject>
1: addMappingWithCode [0x396c722b2119] [/app/node_modules/source-map/lib/source-node.js:~150] [pc=0xd1b26fc691d](this=0x304f7c5044c1 <JSGlobal Object>,0x32d3c4a6d401 <Object map = 0x12d61490c7a9>,0x069a17fc0ae1 <String[18]: var >)
2: /* anonymous */ [0x2863e0300269] [/app/node_modules/source-map/lib/source-node.js:~86] [pc=0xd1b26fc4673...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20210409.212950.23.0.001.json
Node.js report completed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn run build' returned a non-zero code: 1
[Container] 2021/04/09 21:29:51 Command did not exit successfully docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV . exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .. Reason: exit status 1
[Container] 2021/04/09 21:29:51 Entering phase POST_BUILD
[Container] 2021/04/09 21:29:51 Running command bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
[Container] 2021/04/09 21:29:51 Command did not exit successfully bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi" exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: POST_BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi". Reason: exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2021/04/09 21:29:51 Phase context status code: Message: yarn run v1.21.1
$ react-app-rewired build
Creating an optimized production build...
<--- Last few GCs --->
[23:0x55e3d7ad8700] 188895 ms: Mark-sweep 1824.5 (1875.9) -> 1823.0 (1883.6) MB, 1725.5 / 0.0 ms (average mu = 0.109, current mu = 0.013) allocation failure scavenge might not succeed
[23:0x55e3d7ad8700] 191161 ms: Mark-sweep 1831.3 (1884.2) -> 1829.9 (1889.8) MB, 2253.0 / 0.0 ms (average mu = 0.052, current mu = 0.006) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x55e3d5b70342]
Security context: 0x0be28ab9a299 <JSObject>
1: addMappingWithCode [0x396c722b2119] [/app/node_modules/source-map/lib/source-node.js:~150] [pc=0xd1b26fc691d](this=0x304f7c5044c1 <JSGlobal Object>,0x32d3c4a6d401 <Object map = 0x12d61490c7a9>,0x069a17fc0ae1 <String[18]: var >)
2: /* anonymous */ [0x2863e0300269] [/app/node_modules/source-map/lib/source-node.js:~86] [pc=0xd1b26fc4673...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20210409.212950.23.0.001.json
Node.js report completed
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn run build' returned a non-zero code: 1
[Container] 2021/04/09 21:29:51 Command did not exit successfully docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV . exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .. Reason: exit status 1
[Container] 2021/04/09 21:29:51 Entering phase POST_BUILD
[Container] 2021/04/09 21:29:51 Running command bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
[Container] 2021/04/09 21:29:51 Command did not exit successfully bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi" exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: POST_BUILD State: FAILED
[Container] 2021/04/09 21:29:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi". Reason: exit status 1
[Container] 2021/04/09 21:29:51 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2021/04/09 21:29:51 Phase context status code: Message:
The line
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
suggests a memory issue.
So, on AWS I tried: Developer Tools -> CodeBuild -> Build projects -> Edit -> Environment -> Additional Configuration and first increased the compute section from 3 GB memory, 2 vCPUs to 7 GB memory, 4 vCPUs and then from 7 GB memory, 4 vCPUs to 15 GB memory, 8 vCPUs.
Also, I tried adding to the package.json file something like the following and some variations of it:
"start": "react-scripts --max_old_space_size=4096 start",
"build": "set NODE_OPTIONS=--max_old_space_size=512 && react-app-rewired build",
My last try was adding
- export NODE_OPTIONS="--max-old-space-size=8192”
To the command section to the buildspec.yml file.
Here is the scripts part of my package.json file:
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
And here is my buildspec.xml file.
version: 0.2
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- docker login --username ****** --password ‘******’
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- export NODE_OPTIONS="--max-old-space-size=8192”
build:
commands:
- docker build -f Dockerfile-prod -t $REPOSITORY_URI:$BRANCH --build-arg API_URL=$API_URL --build-arg PORTAL_TOKEN=$PORTAL_TOKEN --build-arg REACT_ENV=$REACT_ENV .
- docker tag $REPOSITORY_URI:$BRANCH $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
post_build:
commands:
- bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
- docker push $REPOSITORY_URI:$BRANCH
- docker push $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
- echo Writing image definitions file...
- printf "[{\"name\":\"$TASK_DEFINITION-Instance\",\"imageUri\":\"%s\"}]" $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION > imagedefinitions.json
artifacts:
files: imagedefinitions.json
Any help will be appreciated.
Upvotes: 1
Views: 1795
Reputation: 2357
This is my buildspecs file where I had fixed the issue which I made in the light of your question and the details you put there
version: 0.2
env:
variables:
NODE_ENV: 'development'
phases:
install:
runtime-versions:
nodejs: 12
pre_build:
commands:
- echo Deploy website
build:
commands:
- rm -rf .git
- yarn install
- NODE_OPTIONS="--max-old-space-size=8192"
- yarn build
post_build:
commands:
- echo 'Invalidating distribuition cache'
- aws cloudfront create-invalidation --distribution-id my_id --paths "/*"
Upvotes: 1