简体   繁体   中英

setting start scripts package.json

To start my react app locally, I have to do 3 commands:

cd react-web
npm run postinstall
export REACT_APP_CUSTOMER_ENVIRONMENT=xxx
npm start

once I do this, the apps server starts on my port localhost:3000. For my start script in my package.json , I have this:

 "scripts": {
    "test-web": "cd react-web && npm test && cd ..",
    "test": "npm run test-web",
    "start": "cd react-web && npm run postinstall && export REACT_APP_CUSTOMER_ENVIRONMENT=xxx && npm start"
  },

when I start the app live and take a look at my live logs, I get these errors:

    2021-04-17T19:54:13.501682+00:00 app[web.1]: <--- Last few GCs --->
2021-04-17T19:54:13.501683+00:00 app[web.1]: 
2021-04-17T19:54:13.501687+00:00 app[web.1]: [70:0x5fc0080]   131064 ms: Scavenge (reduce) 252.9 (256.5) -> 252.7 (257.5) MB, 8.1 / 0.0 ms  (average mu = 0.378, current mu = 0.012) allocation failure
2021-04-17T19:54:13.501688+00:00 app[web.1]: [70:0x5fc0080]   131071 ms: Scavenge (reduce) 252.9 (256.5) -> 252.7 (258.2) MB, 4.2 / 0.0 ms  (average mu = 0.378, current mu = 0.012) allocation failure
2021-04-17T19:54:13.501688+00:00 app[web.1]: 
2021-04-17T19:54:13.501688+00:00 app[web.1]: 
2021-04-17T19:54:13.501689+00:00 app[web.1]: <--- JS stacktrace --->
2021-04-17T19:54:13.501689+00:00 app[web.1]: 
2021-04-17T19:54:13.501699+00:00 app[web.1]: FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
2021-04-17T19:54:13.502612+00:00 app[web.1]: 1: 0xa04200 node::Abort() [node]
2021-04-17T19:54:13.503260+00:00 app[web.1]: 2: 0x94e4e9 node::FatalError(char const*, char const*) [node]
2021-04-17T19:54:13.504744+00:00 app[web.1]: 3: 0xb7978e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
2021-04-17T19:54:13.505450+00:00 app[web.1]: 4: 0xb79b07 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
2021-04-17T19:54:13.506269+00:00 app[web.1]: 5: 0xd34395  [node]
2021-04-17T19:54:13.507054+00:00 app[web.1]: 6: 0xd64f2e v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [node]
2021-04-17T19:54:13.507841+00:00 app[web.1]: 7: 0xd70f66 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk*, long*) [node]
2021-04-17T19:54:13.508619+00:00 app[web.1]: 8: 0xd5d14f v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [node]
2021-04-17T19:54:13.515206+00:00 app[web.1]: 9: 0xd5d3c8 v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [node]
2021-04-17T19:54:13.516015+00:00 app[web.1]: 10: 0xd4fca9 v8::internal::ItemParallelJob::Run() [node]
2021-04-17T19:54:13.516870+00:00 app[web.1]: 11: 0xd72ec0 void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::MarkCompactCollector>(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::MigrationObserver*, long) [node]
2021-04-17T19:54:13.517698+00:00 app[web.1]: 12: 0xd7375c v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node]
2021-04-17T19:54:13.518519+00:00 app[web.1]: 13: 0xd73925 v8::internal::MarkCompactCollector::Evacuate() [node]
2021-04-17T19:54:13.519302+00:00 app[web.1]: 14: 0xd85911 v8::internal::MarkCompactCollector::CollectGarbage() [node]
2021-04-17T19:54:13.520074+00:00 app[web.1]: 15: 0xd41c38 v8::internal::Heap::MarkCompact() [node]
2021-04-17T19:54:13.520863+00:00 app[web.1]: 16: 0xd43728 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2021-04-17T19:54:13.521667+00:00 app[web.1]: 17: 0xd46b6c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2021-04-17T19:54:13.522486+00:00 app[web.1]: 18: 0xd1524b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
2021-04-17T19:54:13.523400+00:00 app[web.1]: 19: 0x105b23f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
2021-04-17T19:54:13.524382+00:00 app[web.1]: 20: 0x1401219  [node]
2021-04-17T19:54:13.617429+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-04-17T19:54:13.622561+00:00 app[web.1]: npm ERR! errno 1
2021-04-17T19:54:13.633727+00:00 app[web.1]: npm ERR! react-web@0.1.0 start: `node checkEnvironmentForBuild && react-app-rewired start`
2021-04-17T19:54:13.633968+00:00 app[web.1]: npm ERR! Exit status 1
2021-04-17T19:54:13.634390+00:00 app[web.1]: npm ERR!
2021-04-17T19:54:13.634616+00:00 app[web.1]: npm ERR! Failed at the react-web@0.1.0 start script.
2021-04-17T19:54:13.634831+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-04-17T19:54:13.644582+00:00 app[web.1]: 
2021-04-17T19:54:13.650766+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-17T19:54:13.650974+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-04-17T19_54_13_636Z-debug.log
2021-04-17T19:54:13.678521+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-04-17T19:54:13.679086+00:00 app[web.1]: npm ERR! errno 1
2021-04-17T19:54:13.700823+00:00 app[web.1]: npm ERR! cleaningx@1.0.0 start: `cd react-web && npm run postinstall && export REACT_APP_CUSTOMER_ENVIRONMENT=xxx && npm start`
2021-04-17T19:54:13.701146+00:00 app[web.1]: npm ERR! Exit status 1
2021-04-17T19:54:13.701430+00:00 app[web.1]: npm ERR!
2021-04-17T19:54:13.701646+00:00 app[web.1]: npm ERR! Failed at the cleaningx@1.0.0 start script.
2021-04-17T19:54:13.701884+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-04-17T19:54:13.711066+00:00 app[web.1]: 
2021-04-17T19:54:13.714773+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-17T19:54:13.714960+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-04-17T19_54_13_703Z-debug.log
2021-04-17T19:54:13.811333+00:00 heroku[web.1]: Process exited with status 1
2021-04-17T19:54:13.911608+00:00 heroku[web.1]: State changed from up to crashed

how would I fix this?

It is a memory problem with Heroku. You should increase the memory either through the heroku configuration or directly from node.

Heroku

heroku config:set NODE_OPTIONS='--max_old_space_size=2560 [app-name]'

package.json in react-web.

"start": "node --max_old_space_size=2560 react-app-rewired start"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM