taro prebundle 多端文件打包 报错 Can't resolve,关闭prebundle是正常的

klh5stk1  于 4个月前  发布在  其他
关注(0)|答案(9)|浏览(53)

相关平台

微信小程序

小程序基础库: 2.27.3
使用框架: Vue 3

复现步骤

yarn dev:weapp 多端文件解析报错

多端文件如下:

assets/js/gio/config.alipay.js

assets/js/gio/config.tt.js

assets/js/gio/config.weapp.js

assets/js/gio/index.alipay.js

assets/js/gio/index.tt.js

assets/js/gio/index.weapp.js

业务代码

const gioConfig = require("./assets/js/gio/config").default

const gio = require("./assets/js/gio/index").default

gio("setConfig", gioConfig)

用Taro 3.5.7 init 出来的项目,也会报错

如果过改成

const gioConfig = require("./assets/js/gio/config.weapp").default

let gio = require("./assets/js/gio/index.weapp").default

gio("setConfig", gioConfig)

是正常的

多端文件加载有问题

不关闭prebundle 多端文件解析存在问题

期望结果

编译成功

实际结果

[ERROR] [plugin scanImports] Can't resolve './assets/js/gio/index' in 'D:\frontend\local\myApp\src'

node_modules/enhanced-resolve/lib/Resolver.js:309:17:
  309 │       const error = new Error("Can't "   message);
      ╵                     ^

at finishWithoutResolve (D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\Resolver.js:309:18)
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\Resolver.js:386:15
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\Resolver.js:435:5
at eval (eval at create (D:\frontend\local\myApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\Resolver.js:435:5
at eval (eval at create (D:\frontend\local\myApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:27:1)
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:87:43
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\Resolver.js:435:5
at eval (eval at create (D:\frontend\local\myApp\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:16:1)
at D:\frontend\local\myApp\node_modules\enhanced-resolve\lib\forEachBail.js:16:12

This error came from the "onResolve" callback registered here:

node_modules/esbuild/lib/main.js:855:22:
  855 │         let promise = setup({
      ╵                       ^

at setup (D:\frontend\local\myApp\node_modules\@tarojs\webpack5-prebundle\src\prebundle\scanImports.ts:209:13)
at handlePlugins (D:\frontend\local\myApp\node_modules\esbuild\lib\main.js:855:23)
at Object.buildOrServe (D:\frontend\local\myApp\node_modules\esbuild\lib\main.js:1149:7)
at D:\frontend\local\myApp\node_modules\esbuild\lib\main.js:2110:17
at new Promise (<anonymous>)
at Object.build (D:\frontend\local\myApp\node_modules\esbuild\lib\main.js:2109:14)
at Object.build (D:\frontend\local\myApp\node_modules\esbuild\lib\main.js:1956:51)
at D:\frontend\local\myApp\node_modules\@tarojs\webpack5-prebundle\src\prebundle\scanImports.ts:53:21
at Generator.next (<anonymous>)

The plugin "scanImports" was triggered by this import

src/app.ts:6:18:
  6 │ let gio = require("./assets/js/gio/index").default
    ╵                   ~~~~~~~~~~~~~~~~~~~~~~~

Prebundle dependencies:
@tarojs/plugin-framework-vue3/dist/runtime
@tarojs/plugin-platform-weapp/dist/runtime
@tarojs/runtime
@tarojs/taro
vue

✔ Webpack
Compiled successfully in 3.99s

→ Watching... [2023/2/10 15:25:23]

环境信息

Taro CLI 3.5.7 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 16.17.1 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
ovfsdjhp

ovfsdjhp1#

@Tomoyd 麻烦提供一下 demo

omtl5h9j

omtl5h9j2#

遇到同样问题,请问解决了吗

wj8zmpe1

wj8zmpe15#

+1 脚手架创建的jsx项目出现同样的问题。。。

daolsyd0

daolsyd06#

+1 脚手架创建的jsx项目出现同样的问题。。。,
使用 TS webpack5 react 默认模板
配置打开了
prebundle: {
enable: false,
},
cache: {
enable: true, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
},

lymnna71

lymnna717#

这个我能复现,暂时没时间调试,晚点我找时间搞个demo

nue99wik

nue99wik9#

这个问题 请问有后续不~

相关问题