withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
47.35k stars 2.51k forks source link

🐛 BUG: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory #2279

Closed danramteke closed 2 years ago

danramteke commented 2 years ago

What version of astro are you using?

0.21.13

What package manager are you using?

yarn

What operating system are you using?

Mac

Describe the Bug

Small site renders fine on both my dev machines. When astro build runs as a RUN step inside of a Docker build, it runs out of memory. Increasing the memory using NODE_OPTIONS=--max_old_space_size=8192 still results in failure

Here is the stack trace.

[+] Building 199.0s (16/16) FINISHED                                                                                                                     
 => [internal] load build definition from Dockerfile.build                                                                                          0.0s
 => => transferring dockerfile: 43B                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                   0.0s
 => => transferring context: 34B                                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/node:17                                                                                          0.5s
 => [internal] load build context                                                                                                                   0.1s
 => => transferring context: 5.91MB                                                                                                                 0.1s
 => CACHED [ 1/12] FROM docker.io/library/node:17@sha256:36aca218a5eb57cb23bc790a030591382c7664c15a384e2ddc2075761ac7e701                           0.0s
 => [ 2/12] COPY astro.config.mjs astro.config.mjs                                                                                                  0.0s
 => [ 3/12] COPY package.json package.json                                                                                                          0.0s
 => [ 4/12] COPY postcss.config.cjs postcss.config.cjs                                                                                              0.0s
 => [ 5/12] COPY tailwind.config.cjs tailwind.config.cjs                                                                                            0.0s
 => [ 6/12] COPY vite-env.d.ts vite-env.d.ts                                                                                                        0.0s
 => [ 7/12] COPY vite.config.js vite.config.js                                                                                                      0.0s
 => [ 8/12] COPY yarn.lock yarn.lock                                                                                                                0.0s
 => [ 9/12] COPY src src                                                                                                                            0.0s
 => [10/12] COPY public public                                                                                                                      0.0s
 => [11/12] RUN yarn install                                                                                                                       27.2s
 => ERROR [12/12] RUN yarn build                                                                                                                  170.9s 
------                                                                                                                                                   
 > [12/12] RUN yarn build:                                                                                                                               
#16 0.457 yarn run v1.22.17                                                                                                                              
#16 0.468 warning package.json: No license field                                                                                                         
#16 0.481 $ astro build                                                                                                                                  
#16 170.4                                                                                                                                                
#16 170.4 <--- Last few GCs --->
#16 170.4 
#16 170.4 [29:0x5d42160]   167275 ms: Mark-sweep 2003.1 (2086.3) -> 1987.6 (2087.3) MB, 1201.8 / 2.1 ms  (average mu = 0.185, current mu = 0.152) allocation failure scavenge might not succeed
#16 170.4 [29:0x5d42160]   168692 ms: Mark-sweep 2003.6 (2087.3) -> 1988.8 (2087.5) MB, 1182.6 / 2.1 ms  (average mu = 0.176, current mu = 0.166) allocation failure scavenge might not succeed
#16 170.4 
#16 170.4 
#16 170.4 <--- JS stacktrace --->
#16 170.4 
#16 170.4 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
#16 170.4  1: 0xb2c2b0 node::Abort() [/usr/local/bin/node]
#16 170.4  2: 0xa4025c node::FatalError(char const*, char const*) [/usr/local/bin/node]
#16 170.4  3: 0xd1d11e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
#16 170.4  4: 0xd1d497 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
#16 170.4  5: 0xed68f5  [/usr/local/bin/node]
#16 170.4  6: 0xed73d6  [/usr/local/bin/node]
#16 170.4  7: 0xee704c  [/usr/local/bin/node]
#16 170.4  8: 0xee7ac0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
#16 170.4  9: 0xeeaa6e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
#16 170.4 10: 0xeac48a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
#16 170.4 11: 0x122c8e8 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
#16 170.4 12: 0x162fb79  [/usr/local/bin/node]
#16 170.8 Aborted
#16 170.8 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#16 170.8 error Command failed with exit code 134.
------
executor failed running [/bin/sh -c yarn build]: exit code: 134

Link to Minimal Reproducible Example

https://github.com/danramteke/docker-astro-slow-build

jonathantneal commented 2 years ago

Verified at https://github.com/danramteke/docker-astro-slow-build/runs/4643816143?check_suite_focus=true

Is this the kind of issue that may be resolved behind our upcoming SSR flag, @matthewp?

matthewp commented 2 years ago

I'll have to take a look at the example but yes, most likely it is.

tony-sull commented 2 years ago

Hey, this issue is out of date and may have been fixed in the latest version of Astro. If you can still reproduce the issue with the latest version of astro (npm install astro@next) please open a new issue and we can take a deeper look. :+1:

The latest static build process, used via astro build --experimental-static-build, should take care of this. The flag is only short term and will be swapped out as the default build process in the near future 👍

danramteke commented 2 years ago

@tony-sull @matthewp @jonathantneal looks like this is not resolved using astro@next and --experimental-static-build

Upgrade astro: https://github.com/danramteke/docker-astro-slow-build/runs/5219063956?check_suite_focus=true Upgrade all deps: https://github.com/danramteke/docker-astro-slow-build/runs/5219165788?check_suite_focus=true

benjaminbilgehan commented 3 months ago

I encountered a memory issue, possibly due to Decap CMS. Before running npm run build, I manually deleted the dist folder, and everything worked perfectly. To automate this, I added the following configuration to my package.json:

"clean": "rm -rf dist",
"build": "npm run clean && astro build",