【问题标题】:npm start 以 - 致命错误:MarkCompactCollector:年轻对象提升失败分配失败 - JavaScript 堆内存不足
【发布时间】:2021-10-04 14:52:38
【问题描述】:

所以我正在尝试将我的项目部署到 AWS LightSail 实例

  1. 我克隆了我的仓库
  2. npm 安装
  3. npm 开始。
    然后发生分配失败错误

错误:

<--- JS stacktrace --->

 FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - 
 JavaScript heap out of memory
 1: 0xa222f0 node::Abort() [node]
 2: 0x96411f node::FatalError(char const*, char const*) [node]
 3: 0xb97f1e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) 
 [node]
 4: 0xb98297 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char 
 const*, bool) [node]
 5: 0xd52fd5  [node]
 6:  0xd83bbe v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, 
 int) [node]
 7: 0xd8fbf6 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk*, 
 long*) [node]
 8: 0xd7bd8f v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [node]
 9: 0xd7c008 v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [node]
 10: 0xd6e8e9 v8::internal::ItemParallelJob::Run() [node]
 11: 0xd91b50 void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::Mar
 kCompactCollector>(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::MigrationObserver*, long) [node]
 12: 0xd923ec v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [node]
 13: 0xd925b5 v8::internal::MarkCompactCollector::Evacuate() [node]
 14: 0xda45b1 v8::internal::MarkCompactCollector::CollectGarbage() [node]
 15: 0xd60878 v8::internal::Heap::MarkCompact() [node]
 16: 0xd62368 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace,           v8::internal::GarbageCollectionReason, v8::GCCallbackFlag
 s) [node]
 17: 0xd657ac v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int,      v8::internal::AllocationType, v8::internal::AllocationOrigin, v
 8::internal::AllocationAlignment) [node]
 18: 0xd33e5b v8::internal::Factory::NewFillerObject(int, bool,      v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
 19: 0x107c5af v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
 20: 0x1423279  [node]
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! gui@0.1.0 start: `react-scripts start`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the gui@0.1.0 start 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/bitnami/.npm/_logs/2021-07-28T21_07_20_268Z-debug.log

所以我调查了那个错误和大部分说要使用的:

export NODE_OPTIONS=--max_old_space_size=4096

所以不好的一面是设置SPACE SIZE后没有错误 但是不好的一面是它一直卡在:

> gui@0.1.0 start /opt/bitnami/apache/htdocs/GeThaText/frontend/gui
> react-scripts start
Starting the development server...

我的 package.json:

{
"name": "gui",
"version": "0.1.0",
"private": true,
"dependencies": {
  "@ant-design/icons": "^4.2.1",
  "@material-ui/core": "^4.11.2",
  "@material-ui/icons": "^4.11.2",
  "ant-design": "^1.0.0",
  "antd": "^4.7.0",
  "axios": "^0.21.1",
  "bootstrap": "^4.5.2",
  "dotenv": "^10.0.0",
  "material-table": "^1.69.2",
  "node-sass": "^4.14.1",
  "react": "^16.14.0",
  "react-copy-to-clipboard": "^5.0.2",
  "react-dom": "^16.13.1",
  "react-facebook-login": "^4.1.1",
  "react-google-login": "^5.2.2",
  "react-google-recaptcha": "^2.1.0",
  "react-redux": "^7.2.1",
  "react-router-config": "^5.1.1",
  "react-router-dom": "^5.2.0",
  "react-scripts": "^3.4.2",
  "react-text-loop": "^2.3.0",
  "redux": "^4.0.5",
  "redux-thunk": "^2.3.0"
},
"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
  ">0.2%",
  "not dead",
  "not op_mini all"
],
"development": [
  "last 1 chrome version",
  "last 1 firefox version",
  "last 1 safari version"
]
},
"devDependencies": {
  "eslint": "^6.6.0",
  "eslint-plugin-react": "^7.24.0",
  "less-loader": "^6.2.0",
  "sass": "^1.34.1",
  "sass-loader": "^11.1.1"
}
}

任何想法可能是什么问题???? ?????? (在我的电脑 Macbook M1 上它可以工作)。 P.S 我尝试使用一个简单的 react 项目,效果很好

【问题讨论】:

  • 某些代码似乎存在问题。回购是公开的吗?
  • 可能是,但它确实可以在我的 Mac 上工作,如果它可以工作,这有点奇怪,问题出在代码上(将 repo 链接附加到问题)
  • 在 Mac 上工作,而不是在 PC 上工作?如果您在 PC 上,我会假设是 Windows 10,如果是这种情况,您是否使用 WSL / WSL 2?这可能会让一切变得不同。
  • 光帆实例是Unix所以与Windows无关

标签: node.js reactjs amazon-web-services npm amazon-lightsail


【解决方案1】:

我的结论

您可能会遇到运行时错误,并且由于您是在 lightail 上运行,因此错误可能会发送到某处的日志中,而不是您的控制台。

我为什么这么说

我在本地下载并安装了您的 repo (w10h wsl1)。安装顺利,但在运行时我遇到了错误,其中来自ComponentsContainers 的任何imports 都失败了,因为文件树中的文件夹名称是小写的。在对两个文件夹名称进行整个项目查找和替换后,项目按预期启动。

干杯

【讨论】:

    【解决方案2】:

    虽然我对 AWS Lightsail 的相关细节缺乏了解,但这种行为看起来像是内存不足的典型示例。基本上,当内存使用量接近极限时,系统正在交换或尝试 GC 时,性能将停止(可能表现为冻结或挂起)。

    维基百科有一个 brief entry 说明如何通过虚拟内存/交换实现这一点:

    当系统内存对于当前任务而言严重不足并且大部分内存活动都经历了缓慢的交换时,即使 CPU 处于空闲状态,系统实际上也可能无法执行任何任务。当每个进程都在等待交换时,系统被认为处于交换死亡状态。

    由于内存过度使用配置不正确,可能会导致交换死亡。

    “swapping to death”问题的原始描述与 X 服务器有关。如果 X 服务器用于响应击键的代码或数据不在主内存中,那么如果用户输入击键,服务器将出现一个或多个页面错误,要求在击键之前从交换中读取这些页面。处理,减慢对它的响应。如果这些页面没有保留在内存中,它们将不得不再次出现故障以处理下一次击键,从而使系统实际上没有响应,即使它实际上正在正常执行其他任务。

    您的选择是减少内存使用或为任务提供额外的内存。

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2021-06-12
      • 2021-03-21
      • 2018-07-06
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 2018-09-25
      相关资源
      最近更新 更多