uni-app hbuildx 4.36 运行到小程序经常报错

发布于 1周前 作者 wuwangju 来自 Uni-App

uni-app hbuildx 4.36 运行到小程序经常报错

测试过的手机:

微信小程序

操作步骤:

  • 运行到微信小程序

预期结果:

  • 不报错

实际结果:

17:01:53.882 开始差量编译… 17:01:59.066 项目 ‘项目名称’ 编译成功。前端运行日志,请另行在小程序开发工具的控制台查看。 17:03:02.648 开始差量编译… 17:03:09.376 <— Last few GCs —> 17:03:09.383 [17552:000001CFBC440080] 164599 ms: Mark-sweep (reduce) 2033.5 (2083.9) -> 2032.7 (2084.2) MB, 516.4 / 0.0 ms (average mu = 0.339, current mu = 0.003) allocation failure; scavenge might not succeed 17:03:09.389 [17552:000001CFBC440080] 165725 ms: Mark-sweep (reduce) 2033.8 (2084.2) -> 2033.0 (2084.4) MB, 1124.3 / 0.0 ms (average mu = 0.135, current mu = 0.002) allocation failure; scavenge might not succeed 17:03:09.396 <— JS stacktrace —> 17:03:09.403 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 17:03:09.702 1: 00007FF703C35AFF node_api_throw_syntax_error+174175 17:03:09.710 2: 00007FF703BB8F26 v8::internal::wasm::WasmCode::safepoint_table_offset+59926 17:03:09.719 3: 00007FF703BBABC0 v8::internal::wasm::WasmCode::safepoint_table_offset+67248 17:03:09.727 4: 00007FF704666224 v8::Isolate::ReportExternalAllocationLimitReached+116 17:03:09.736 5: 00007FF7046515B2 v8::Isolate::Exit+674 17:03:09.744 6: 00007FF7044D327C v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124 17:03:09.753 7: 00007FF7044D049B v8::internal::Heap::CollectGarbage+3963 17:03:09.762 8: 00007FF7044E66D3 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099 17:03:09.770 9: 00007FF7044E6F7D v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93 17:03:09.774 10: 00007FF7044F6740 v8::internal::Factory::NewFillerObject+816 17:03:09.790 11: 00007FF7041E7145 v8::internal::DateCache::Weekday+1349 17:03:09.794 12: 00007FF704704121 v8::internal::SetupIsolateDelegate::SetupHeap+558257 17:03:09.812 13: 00007FF7046E5E51 v8::internal::SetupIsolateDelegate::SetupHeap+434657 17:03:09.828 14: 00007FF6855ABFAD

bug描述:

运行项目到小程序 报错 17:01:53.882 开始差量编译… 17:01:59.066 项目 ‘项目名称’ 编译成功。前端运行日志,请另行在小程序开发工具的控制台查看。 17:03:02.648 开始差量编译… 17:03:09.376 <— Last few GCs —> 17:03:09.383 [17552:000001CFBC440080] 164599 ms: Mark-sweep (reduce) 2033.5 (2083.9) -> 2032.7 (2084.2) MB, 516.4 / 0.0 ms (average mu = 0.339, current mu = 0.003) allocation failure; scavenge might not succeed 17:03:09.389 [17552:000001CFBC440080] 165725 ms: Mark-sweep (reduce) 2033.8 (2084.2) -> 2033.0 (2084.4) MB, 1124.3 / 0.0 ms (average mu = 0.135, current mu = 0.002) allocation failure; scavenge might not succeed 17:03:09.396 <— JS stacktrace —> 17:03:09.403 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory 17:03:09.702 1: 00007FF703C35AFF node_api_throw_syntax_error+174175 17:03:09.710 2: 00007FF703BB8F26 v8::internal::wasm::WasmCode::safepoint_table_offset+59926 17:03:09.719 3: 00007FF703BBABC0 v8::internal::wasm::WasmCode::safepoint_table_offset+67248 17:03:09.727 4: 00007FF704666224 v8::Isolate::ReportExternalAllocationLimitReached+116 17:03:09.736 5: 00007FF7046515B2 v8::Isolate::Exit+674 17:03:09.744 6: 00007FF7044D327C v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124 17:03:09.753 7: 00007FF7044D049B v8::internal::Heap::CollectGarbage+3963 17:03:09.762 8: 00007FF7044E66D3 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099 17:03:09.770 9: 00007FF7044E6F7D v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93 17:03:09.774 10: 00007FF7044F6740 v8::internal::Factory::NewFillerObject+816 17:03:09.790 11: 00007FF7041E7145 v8::internal::DateCache::Weekday+1349 17:03:09.794 12: 00007FF704704121 v8::internal::SetupIsolateDelegate::SetupHeap+558257 17:03:09.812 13: 00007FF7046E5E51 v8::internal::SetupIsolateDelegate::SetupHeap+434657 17:03:09.828 14: 00007FF6855ABFAD


1 回复

在处理uni-app在HBuilderX 4.36中运行到小程序时遇到的频繁报错问题时,首先需要确保开发环境配置正确,并且代码符合小程序的规范。以下是一些常见的错误排查方法和相关代码示例,帮助你定位和解决可能的问题。

1. 检查项目配置

确保manifest.json中的小程序配置正确,例如appid、项目名称等。

{
  "mp-weixin": { // 微信小程序配置示例
    "appid": "your-app-id",
    "setting": {
      "urlCheck": false
    }
  }
}

2. 检查代码规范

小程序对代码规范有严格要求,确保没有使用小程序不支持的API或语法。

示例:避免使用不支持的API

// 错误示例:使用了不支持的DOM操作
// document.getElementById('someId').style.display = 'none';

// 正确示例:使用uni-app提供的API
uni.hideToast();

3. 调试和日志

利用HBuilderX的调试功能和小程序的开发者工具查看具体的错误信息。

示例:使用console打印调试信息

onLoad() {
    console.log('Page loaded');
    // 其他初始化代码
}

4. 资源路径问题

确保资源文件(如图片、字体等)的路径正确无误。

示例:正确的图片路径

<image src="/static/images/logo.png" mode="widthFix"></image>

5. 组件和页面注册

确保所有页面和组件都在pages.json中正确注册。

{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "首页"
      }
    }
  ]
}

6. 网络请求

小程序对网络请求有严格限制,确保请求合法且已配置合法域名。

示例:合法的网络请求

uni.request({
    url: 'https://example.com/api/data', // 确保域名已在小程序后台配置
    success: (res) => {
        console.log(res.data);
    },
    fail: (err) => {
        console.error(err);
    }
});

结论

如果以上方法仍未解决你的问题,建议详细查看HBuilderX的控制台输出和小程序开发者工具的详细错误信息,这些信息通常能提供更具体的错误原因。同时,确保你的uni-app和HBuilderX都是最新版本,以利用最新的功能和修复。

回到顶部