uni-app 华为 mate 20 打了自定义包同步上去报 require is not defined

uni-app 华为 mate 20 打了自定义包同步上去报 require is not defined

reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught ReferenceError: require is not defined

3 回复

点击debug按钮看看,是否有更详细的报错

更多关于uni-app 华为 mate 20 打了自定义包同步上去报 require is not defined的实战教程也可以访问 https://www.itying.com/category-93-b0.html


你好,问题有解决吗,我也遇到了一样的问题

这个报错是因为华为 mate 20 等部分 Android 设备在 WebView 内核版本较低时,不支持 CommonJS 的 require 语法。uni-app 在自定义打包时,默认会将模块转换为 CommonJS 格式,导致在低版本 WebView 中运行时报错。

解决方案:

  1. 修改打包配置:manifest.json 中配置使用 es 模块格式:
    {
      "app-plus": {
        "modules": {
          "es": true
        }
      }
    }
回到顶部