Skip to content

开启半编译模式 —— CompileMode报错 #15252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hcweb opened this issue Feb 21, 2024 · 6 comments · May be fixed by #17583
Open

开启半编译模式 —— CompileMode报错 #15252

hcweb opened this issue Feb 21, 2024 · 6 comments · May be fixed by #17583
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@hcweb
Copy link

hcweb commented Feb 21, 2024

微信图片_20240221190532

相关平台

微信小程序

小程序基础库: 3.3.3
使用框架: React

复现步骤

按照文档开启半编译模式 —— CompileMode报错

期望结果

开启半编译模式 —— CompileMode报错

实际结果

开启半编译模式 —— CompileMode报错

环境信息

👽 Taro v3.6.23


  Taro CLI 3.6.23 environment info:
    System:
      OS: Windows 11 10.0.22621
    Binaries:
      Node: 18.19.0 - D:\soft\node18\node.EXE
      Yarn: 1.22.21 - D:\npm_wrokspace\yarn.CMD
      npm: 10.4.0 - D:\soft\node18\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.23 => 3.6.23
      @tarojs/components: 3.6.23 => 3.6.23
      @tarojs/helper: 3.6.23 => 3.6.23
      @tarojs/plugin-framework-react: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-alipay: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-h5: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-jd: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-qq: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-swan: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-tt: 3.6.23 => 3.6.23
      @tarojs/plugin-platform-weapp: 3.6.23 => 3.6.23
      @tarojs/react: 3.6.23 => 3.6.23
      @tarojs/runtime: 3.6.23 => 3.6.23
      @tarojs/shared: 3.6.23 => 3.6.23
      @tarojs/taro: 3.6.23 => 3.6.23
      @tarojs/taro-loader: 3.6.23 => 3.6.23
      @tarojs/webpack5-runner: 3.6.23 => 3.6.23
      babel-preset-taro: 3.6.23 => 3.6.23
      eslint-config-taro: 3.6.23 => 3.6.23
      react: ^18.0.0 => 18.2.0
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Feb 21, 2024
@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 1, 2024

@hcweb 麻烦提供一下demo

@Chen-jj Chen-jj added the question Further information is requested label Mar 1, 2024
@w599098780
Copy link

解决了吗?同样的报错

@ct-0902
Copy link

ct-0902 commented Jul 2, 2024

@hcweb 麻烦提供一下demo

目前我这也出现这个问题了,这个是因为windows下开启compileMode,template里面的相对路径会被编译成/导致引用路径找不到,只能先手动改成\才能正常访问,mac下是没有问题的。并且compileMode下引入的wxs相对路径在template模版里也是不对的。

@zhang0ZGC
Copy link

@hcweb 麻烦提供一下demo

目前我这也出现这个问题了,这个是因为windows下开启compileMode,template里面的相对路径会被编译成/导致引用路径找不到,只能先手动改成\才能正常访问,mac下是没有问题的。并且compileMode下引入的wxs相对路径在template模版里也是不对的。

想知道目前这个问题有进展嘛

@UzumakiHan
Copy link

一样的问题

@zhang0ZGC
Copy link

zhang0ZGC commented Apr 11, 2025

问题在这里:

const source = new ConcatSource()
source.add(`<import src="${path.relative(path.dirname(key), `./${baseTemplName}`)}"/>\n`)
if (fileType.xs) {
const content = template.buildXsImportTemplate(path.relative(path.dirname(key), `./utils`))
source.add(content)
}
source.add(assets[key])

windows系统下使用path.relative方法编译出来文件的相对目录变成 ..\..\utils.wxs,但是\很多时候用来表示后面的字符需要保留,所以实际上微信开发者工具找的文件是 ....utils.wxs

临时解决可以找到这个文件 node_modules/@tarojs/webpack5-runner/dist/plugins/MiniCompileModePlugin.js:288,288、290 行把目录分隔符\替换成/就行了,可以再配合patch-package工具固定下修改

source.add(`<import src="${node_path_1.default.relative(node_path_1.default.dirname(key), `./${baseTemplName}`)}"/>\n`);
if (fileType.xs) {
    const content = template.buildXsImportTemplate(node_path_1.default.relative(node_path_1.default.dirname(key), `./utils`));
    source.add(content);
}
source.add(assets[key]);

改成

const repalceSeparator = (path) => {
    return path.replace(/\\/g, '/');
};
source.add(`<import src="${repalceSeparator(node_path_1.default.relative(node_path_1.default.dirname(key), `./${baseTemplName}`))}"/>\n`);
if (fileType.xs) {
    const content = template.buildXsImportTemplate(repalceSeparator(node_path_1.default.relative(node_path_1.default.dirname(key), `./utils`)));
    source.add(content);
}
source.add(assets[key]);

zhang0ZGC added a commit to zhang0ZGC/taro that referenced this issue Apr 15, 2025
zhang0ZGC added a commit to zhang0ZGC/taro that referenced this issue Apr 21, 2025
zhang0ZGC added a commit to zhang0ZGC/taro that referenced this issue Apr 21, 2025
@zhang0ZGC zhang0ZGC linked a pull request Apr 21, 2025 that will close this issue
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

6 participants