Taro.navigateTo跳转独立分包(independent)的页面报错(compiler: 'webpack5')

7vhp5slm  于 1个月前  发布在  Webpack
关注(0)|答案(1)|浏览(44)

相关平台

微信小程序

复现仓库

git@github.com:zhishaofei3/taro-navigateto-independent-project.git
**小程序基础库: 3.2.4**
使用框架: React

复现步骤

注:本地Taro版本 v3.6.20

经排查发现 如过config/index.js的编译器用了webpack5就会出现异常

compiler: {
  type: 'webpack5',
  prebundle: {
    enable: true // 关闭或者使用webpack4正常,开启时报错
  },
},

页面中有两个按钮
第一个按钮(跳转至分包PageA)正常
第二个按钮(跳转至独立分包PageD) 报错

app.config.js:
subPackages: [{
  root: "moduleA",
  pages: [
    'pages/pageA/index'
  ],
}, {
  root: "moduleB",
  pages: [
    'pages/pageD/index'
  ],
  independent: true
}
index.jsx:
function onClickPageDBtn () {
  Taro.navigateTo({
    url: '/moduleB/pages/pageD/index',
    complete: (res) => {
      console.log('zsf www pageD', res) // errMsg: "navigateTo:ok"
    }
  })
}
页面【moduleB/custom-wrapper]错误:
 TypeError: __webpack_modules__[moduleId] is not a function
    at __webpack_require__ (webpack_bootstrap:19)
    at Object../node_modules/@tarojs/webpack5-runner/dist/template/custom-wrapper.js (.._.._src_template_custom-wrapper.ts:2)
    at __webpack_require__ (webpack_bootstrap:19)
    at __webpack_exec__ (custom-wrapper.js:7)
    at custom-wrapper.js:8
    at Function.__webpack_require__.O (webpack_runtime_chunk loaded:25)
    at custom-wrapper.js:9
    at webpackJsonpCallback (webpack_runtime_jsonp chunk loading:74)
    at custom-wrapper.js:5
    at WASubContext.js?t=wechat&s=1702366915661&v=3.2.4:1(env: macOS,mp,1.06.2310080; lib: 3.2.4)

期望结果

正常跳转到独立分包的pageD页面

实际结果

报错 白屏

环境信息

Taro CLI 3.6.20 environment info:
    System:
      OS: macOS 12.6.3
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 16.14.2 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 8.5.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.20 => 3.6.20 
      @tarojs/components: 3.6.20 => 3.6.20 
      @tarojs/helper: 3.6.20 => 3.6.20 
      @tarojs/plugin-framework-react: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-alipay: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-h5: ^3.6.19 => 3.6.19 
      @tarojs/plugin-platform-jd: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-qq: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-swan: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-tt: 3.6.20 => 3.6.20 
      @tarojs/plugin-platform-weapp: 3.6.20 => 3.6.20 
      @tarojs/react: 3.6.20 => 3.6.20 
      @tarojs/runtime: 3.6.20 => 3.6.20 
      @tarojs/shared: 3.6.20 => 3.6.20 
      @tarojs/taro: 3.6.20 => 3.6.20 
      @tarojs/taro-loader: 3.6.20 => 3.6.20 
      @tarojs/webpack5-runner: 3.6.20 => 3.6.20 
      babel-preset-taro: 3.6.20 => 3.6.19 
      eslint-config-taro: 3.6.20 => 3.6.20 
      react: ^18.0.0 => 18.2.0

补充信息

注:本地Taro版本 v3.6.20

相关问题