npm run build not working on EC2 instance

0

I have an Amazon Linux 2023 EC2 Instance. I have a node app on this instance and when I run 'npm run dev', it runs fine, but when I run 'npm run build' It doesn't. I am able to run both commands on my local terminal fine with no issues.

When I run 'npm run build' on the EC2 instance, I get the following error:

transforming (2092) node_modules/zrender/lib/animation/easing.jsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification

<--- Last few GCs --->

[1316431:0x63d0810] 88078 ms: Mark-Compact 468.0 (485.6) -> 464.1 (485.9) MB, 1105.19 / 0.00 ms (average mu = 0.275, current mu = 0.310) allocation failure; scavenge might not succeed [1316431:0x63d0810] 89129 ms: Mark-Compact 468.1 (485.9) -> 464.8 (486.6) MB, 976.06 / 0.00 ms (average mu = 0.203, current mu = 0.071) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xc8e4a0 node::Abort() [node] 2: 0xb6b8f3 [node] 3: 0xeacb10 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 4: 0xeacdf7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 5: 0x10be465 [node] 6: 0x10be9f4 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node] 7: 0x10d58e4 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node] 8: 0x10d60fc v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0x10ac401 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 10: 0x10ad595 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 11: 0x108ab06 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node] 12: 0x14e5936 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node] 13: 0x191eef6 [node]

I then try running export NODE_OPTIONS="--max-old-space-size=1024" to increase the heap limit but when I run build after this, it just seems to hang forever at the below:

transforming (2086) node_modules/zrender/lib/svg/cssAnimation.jsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification ✓ 2094 modules transformed.

I have tried on Amazon linux 2023 and Amazon Linux 2, with both producing the same issue.

질문됨 10달 전1631회 조회
2개 답변
0

@mattNodex You have not specified the ec2 instance type only then we could understand the system capacity. Assuming that you have only one process running to build the app, based on the logs it seems it has failed around 450MB. And once you increased the old space to export NODE_OPTIONS="--max-old-space-size=1024" it failed again, not sure if this memory allocation is possible until you have the system free space. Yet your new error suggest you can disable minification to see if it works.

Again do mention the instance type/size and the other process actively running in it next time.

profile picture
답변함 10달 전
  • Thanks for your reply. No other processes running, this is a brand new instance I created only to run this node app. Instance type is t2.micro Let me know if anything else you need to know.

0

Hi,

In your last comment you mention that you are using a t2.micro, which has 1GiB of RAM. Would it be possible for you to test it on a t2.small instance that has 2 GiB of RAM and rule out a problem related to lack of memory? After all, when you set "max-old-space-size = 1024", Node.js doesn't have all the memory at its disposal, since the operating system itself and other processes also make use of it.

profile picture
전문가
답변함 10달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠