Javascript 在ec2中为reactjs运行npm start时出错

Javascript 在ec2中为reactjs运行npm start时出错,javascript,node.js,reactjs,amazon-ec2,heap-memory,Javascript,Node.js,Reactjs,Amazon Ec2,Heap Memory,我试图在AWS ec2上部署我的node和react应用程序,node应用程序工作正常,但react应用程序在npm run build上出现错误 也尝试了npm start,但仍然得到相同的错误。 这里是错误 已尝试设置节点\u选项=--max\u old\u space\u size=8172以增加内存,但错误保持不变 Security context: 0x0f19d05408a1 <JSObject> 2: visitQueue [0x581c2dbffa1] [/h

我试图在AWS ec2上部署我的node和react应用程序,node应用程序工作正常,但react应用程序在npm run build上出现错误

也尝试了npm start,但仍然得到相同的错误。 这里是错误

已尝试设置节点\u选项=--max\u old\u space\u size=8172以增加内存,但错误保持不变

Security context: 0x0f19d05408a1 <JSObject>
    2: visitQueue [0x581c2dbffa1] [/home/ubuntu/expert-erp/source/node_modules/@babel/traverse/lib/context.js:~96] [pc=0x302cbe090747](this=0x2c145b2a5559 <TraversalContext map = 0x32c1b0aaf1e1>,0x2c145b2a55a1 <JSArray[1]>)
    3: visitMultiple [0x581c2dbbd11] [/home/ubuntu/expert-erp/source/node_modules/@babel/traverse/lib/contex...

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

Writing Node.js report to file: report.20191008.111057.11400.0.001.json
Node.js report completed
 1: 0x9d33e0 node::Abort() [node]
 2: 0x9d4596 node::OnFatalError(char const*, char const*) [node]
 3: 0xb32dbe v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb33139 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xcde455  [node]
 6: 0xcdeae6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
 7: 0xcea97a v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 8: 0xceb885 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 9: 0xcee298 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
10: 0xcb4bc7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType) [node]
11: 0xfeaafb v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x136d539  [node]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Expert-Board@0.0.1 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Expert-Board@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2019-10-08T11_10_57_852Z-debug.log
安全上下文:0x0f19d05408a1
2:visitQueue[0x581c2dbffa1][/home/ubuntu/expert erp/source/node_modules/@babel/traverse/lib/context.js:~96][pc=0x302cbe090747](this=0x2c145b2a559,0x2c145b2a55a1)
3:visitMultiple[0x581C2DBD11][/home/ubuntu/expert erp/source/node_modules/@babel/traverse/lib/contex。。。
致命错误:无效的标记压缩接近堆限制分配失败-JavaScript堆内存不足
正在将Node.js报告写入文件:report.20191008.111057.11400.0.001.json
Node.js报告已完成
1:0x9d33e0节点::中止()[节点]
2:0x9d4596节点::OnFatalError(字符常量*,字符常量*)[node]
3:0xb32dbe v8::Utils::ReportOOMFailure(v8::internal::Isolate*,char const*,bool)[节点]
4:0xb33139 v8::internal::v8::FatalProcessOutOfMemory(v8::internal::Isolate*,char const*,bool)[节点]
5:0xcde455[节点]
6:0xcdeae6 v8::内部::堆::重新计算文件(v8::内部::垃圾收集器)[节点]
7:0xcea97a v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector,v8::GCCallbackFlags)[节点]
8:0xceb885 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace,v8::internal::GarbageCollectionReason,v8::GCCallbackFlags)[节点]
9:0xcee298 v8::internal::Heap::AllocateRawWithRetryOrFail(int,v8::internal::AllocationType,v8::internal::AllocationIgment)[节点]
10:0xcb4bc7 v8::internal::Factory::NewFillerObject(int,bool,v8::internal::AllocationType)[节点]
11:0xfeaafb v8::internal::Runtime_AllocateInYoungGeneration(int,unsigned long*,v8::internal::Isolate*)[节点]
12:0x136d539[节点]
npm错误!代码错误周期
npm错误!错误1
npm错误!专家-Board@0.0.1build:`react脚本build`
npm错误!退出状态1
npm错误!
npm ERR!在专家处失败-Board@0.0.1构建脚本。
npm错误!这可能不是npm的问题。上面可能还有其他日志输出。
npm ERR!此运行的完整日志可在以下位置找到:
npm ERR!/home/ubuntu/.npm/_logs/2019-10-08T11_10_57_852Z-debug.log

如果您正在使用react脚本或创建react应用程序,则可以尝试以下操作:


react-scripts--max_old_space_size=8172 start

该问题与react-scripts空间大小无关

这是EC2实例大小的问题,在增加了实例的内存后,它运行得非常好

(注意:我尝试在EC2免费层上运行它,该层附带8GB SSD和0.8GB RAM,不足以在同一个实例上运行两个应用程序。但将实例更改为2GB RAM后,根本没有问题。)