Skip to content
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

3.6.24开始一直到最新的3.6.26我的库一直编译失败,看报错像是jsx不支持了? #15515

Closed
zhipenglin opened this issue Apr 16, 2024 · 9 comments
Assignees
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@zhipenglin
Copy link

相关平台

微信小程序

复现仓库

https://github.com/kne-union/antd-taro.git
小程序基础库: 2.24.6
使用框架: React

复现步骤

目前项目代码是没有问题的,但是将package.json中有关taro的包版本改到3.6.24及其以上时就会报错

✖ Errors: 

ModuleParseError: Module parse failed: Unexpected token (3304:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const BaseExample = ()=>{
|     return (
>       <Space direction={'vertical'} size={30}>
|         <Space direction={'vertical'}>
|           <View>基础用法</View>

→ Watching... [2024/4/16 10:16:11]

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "
[object Array]".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v18.18.2
ERROR: "start:example" exited with 1.

项目启动方法: npm run init && npm run start

期望结果

编译通过

实际结果

编译报错

环境信息

👽 Taro v3.6.26


  Taro CLI 3.6.26 environment info:
    System:                                                                                         
      OS: Windows 10 10.0.19044
    Binaries:
      Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: ^3.6.26 => 3.6.26
      @tarojs/helper: file:../node_modules/@tarojs/helper => 3.6.26
      @tarojs/mini-runner: ^3.6.26 => 3.6.26
      @tarojs/plugin-framework-react: file:../node_modules/@tarojs/plugin-framework-react => 3.6.26 
      @tarojs/plugin-platform-weapp: file:../node_modules/@tarojs/plugin-platform-weapp => 3.6.26   
      @tarojs/react: file:../node_modules/@tarojs/react => 3.6.26
      @tarojs/runtime: file:../node_modules/@tarojs/runtime => 3.6.26
      @tarojs/shared: file:../node_modules/@tarojs/shared => 3.6.26
      @tarojs/taro: file:../node_modules/@tarojs/taro => 3.6.26
      @tarojs/taro-loader: ^3.6.26 => 3.6.26
      @tarojs/webpack5-runner: ^3.6.26 => 3.6.26
      babel-preset-taro: ^3.6.26 => 3.6.26
      eslint-config-taro: ^3.6.26 => 3.6.26
      react: file:../node_modules/react => 18.2.0

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Apr 16, 2024
This was referenced Apr 20, 2024
@hcw2175
Copy link

hcw2175 commented Apr 22, 2024

+1

image

从 3.6.27 降回 3.6.22,恢复正常。

@levidcd
Copy link

levidcd commented May 6, 2024

+1, 现在锁定3.6.24了

@xiaof520
Copy link
Contributor

有解决办法吗

@hcw2175
Copy link

hcw2175 commented Jun 18, 2024

+1

image

从 3.6.27 降回 3.6.22,恢复正常。

再次升级到 3.6.32,发下问题依然存在。排查了一下原因发现:monorepo 架构,pnpm 管理,项目引用了某个 workspace 模块就会报错,移除依赖就正常了。

估计是 Taro 3.6.25 修改了某个配置导致编译失败,降回 3.6.24 编译正常

希望快点修复,不然想升级都升级不了。

@eiinu
Copy link
Contributor

eiinu commented Jun 18, 2024

可参考
jd-opensource/nutui#3091

@hcw2175
Copy link

hcw2175 commented Jun 19, 2024

可参考 jdf2e/nutui#3091

分别在 mini、h5 节点中加了 complie.include 配置就可以了!为啥这样搞啊?

...
mini: {
      // 解决 Taro 3.6.25 以上版本编译不通过问题
      compile: {
        include: [
          path.resolve(__dirname, '../shared')
        ]
      }
}
h5: {
      // 解决 Taro 3.6.25 以上版本编译不通过问题
      compile: {
        include: [
          path.resolve(__dirname, '../shared')
        ]
      },
}
...

@anyesu
Copy link
Contributor

anyesu commented Jul 6, 2024

可参考 jdf2e/nutui#3091

分别在 mini、h5 节点中加了 complie.include 配置就可以了!为啥这样搞啊?

...
mini: {
      // 解决 Taro 3.6.25 以上版本编译不通过问题
      compile: {
        include: [
          path.resolve(__dirname, '../shared')
        ]
      }
}
h5: {
      // 解决 Taro 3.6.25 以上版本编译不通过问题
      compile: {
        include: [
          path.resolve(__dirname, '../shared')
        ]
      },
}
...

参考这个评论 #15480 (comment) ,应该是同一个问题。

针对题主的项目,出错的只是 example 子项目,不影响 lib 的编译。

出错的代码位于 example/src/pages/index/index.js

import componentsDoc from 'components-doc';
const alias = {
  lodash: '@kne/lodash-wechat',
  'components-doc': require.resolve('../components-doc.js')
};

对应的修复:

const path = require('node:path');

const config = {
  // ...
  mini: {
    // ...
    compile: {
      include: [path.resolve(__dirname, '../components-doc.js')],
    },
  },
  h5: {
    // ...
    compile: {
      include: [path.resolve(__dirname, '../components-doc.js')],
    },
  },
};

最后


提问题最好提供 最小复现项目 ,毕竟别人没时间研究你的项目结构的话,这个问题不就不了了之了。

@zhipenglin
Copy link
Author

我明白了,出现这个问题的原因应该是之前版本alias也会走Babel编译,新版本Babel不会编译alias里面配置的文件了,或者是因为babel的loader新加了什么目录排除逻辑?

@anyesu
Copy link
Contributor

anyesu commented Jul 20, 2024

我明白了,出现这个问题的原因应该是之前版本alias也会走Babel编译,新版本Babel不会编译alias里面配置的文件了,或者是因为babel的loader新加了什么目录排除逻辑?

3.6.25 起, babel-loader 默认编译范围( 即 compile 配置 )从 非 node_modules 范围收缩为 src 范围。( 具体分析见 #15480 (comment)

@tutuxxx tutuxxx self-assigned this Nov 28, 2024
@tutuxxx tutuxxx added this to the 4.0.8 milestone Nov 28, 2024
@tutuxxx tutuxxx closed this as completed Dec 2, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Mini Program Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
Archived in project
Development

No branches or pull requests

7 participants