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

使用v4.0.4脚手架安装 react vite 版本 编译微信小程序报错 #16226

Open
DankeBIBI opened this issue Aug 2, 2024 · 23 comments
Open
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@DankeBIBI
Copy link

相关平台

微信小程序

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

复现步骤

正常使用taro 命令创建项目,然后 dev:weapp

首先缺少
✓ 1 modules transformed.
[babel] [BABEL] D:\project\react-test\D:\project\react-test\src\app.ts?entry-loader=true: Cannot find module '@babel/preset-react'

然后缺少
✓ 1 modules transformed.
[babel] [BABEL] D:\project\react-test\D:\project\react-test\src\app.ts?entry-loader=true: Cannot find module '@babel/plugin-proposal-class-properties'

然后安装依赖完毕后 run dev:weapp

微信开发工具控制台报

app.js错误:
TypeError: taro.getDefaultExportFromCjs is not a function

期望结果

正常运行

实际结果

报错

环境信息

👽 Taro v4.0.4


  Taro CLI 4.0.4 environment info:
    System:
      OS: Windows 11 10.0.22631
    Binaries:
      Node: 18.20.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
      npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 4.0.4 => 4.0.4
      @tarojs/components: 4.0.4 => 4.0.4
      @tarojs/helper: 4.0.4 => 4.0.4
      @tarojs/plugin-framework-react: 4.0.4 => 4.0.4
      @tarojs/plugin-html: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-alipay: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-h5: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-jd: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-qq: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-swan: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-tt: 4.0.4 => 4.0.4
      @tarojs/plugin-platform-weapp: 4.0.4 => 4.0.4
      @tarojs/react: 4.0.4 => 4.0.4
      @tarojs/runtime: 4.0.4 => 4.0.4
      @tarojs/shared: 4.0.4 => 4.0.4
      @tarojs/taro: 4.0.4 => 4.0.4
      @tarojs/vite-runner: 4.0.4 => 4.0.4
      babel-preset-taro: 4.0.4 => 4.0.4
      eslint-config-taro: 4.0.4 => 4.0.4
      react: ^18.0.0 => 18.3.1
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Aug 2, 2024
@zyh9
Copy link

zyh9 commented Aug 2, 2024

  1. @babel/preset-react
  2. @babel/plugin-proposal-class-properties
  3. @tarojs/binding-darwin-arm64 「主要针对 ARM 架构芯片」

装一下依赖就好啦

This was referenced Aug 3, 2024
@TheKonka
Copy link
Member

TheKonka commented Aug 4, 2024

想入坑, 怎奈报错太多, 我taro+vite+sass +nutui+react, 他连wxss 文件都没给我生成 安装 依赖还要加--force, 运行起来页面空白,各种报错

可以先用v3, v4 刚出,坑是不少

@DankeBIBI
Copy link
Author

  1. @babel/preset-react
  2. @babel/plugin-proposal-class-properties
  3. @tarojs/binding-darwin-arm64 「主要针对 ARM 架构芯片」

装一下依赖就好啦

好的,我尝试下

@DankeBIBI
Copy link
Author

想入坑, 怎奈报错太多, 我taro+vite+sass +nutui+react, 他连wxss 文件都没给我生成 安装 依赖还要加--force, 运行起来页面空白,各种报错

我本来想把uni-vue3 重构成taro-react的,结果我按着文档来拉模板都会少依赖

@skylingfly
Copy link

mark, 依然启动起来报错 TypeError: taro.getDefaultExportFromCjs is not a function

@Phyzait
Copy link

Phyzait commented Aug 7, 2024

mark, 依然启动起来报错 TypeError: taro.getDefaultExportFromCjs is not a function

package.json->browserslist 改成这样

{
  "browserslist": [
      "defaults and fully supports es6-module",
      "maintained node versions"
    ],
}

但是Form的children显示不出来,目前没试其他组件

@pdb3616109
Copy link

原来不止我一个人这样😭

@maoxia1990
Copy link

直接用其模板,同样问题加,最新版本:v4.0.5。
image

image

@logeast
Copy link

logeast commented Sep 24, 2024

求解决方案,mac m1 报错

@dyt123456
Copy link

直接用其模板,同样问题加,最新版本:v4.0.5。 图像

图像

我也出现了一模一样的问题 请问你解决了吗?我用yarn命令去引用其react-NutUI模板就不得行

@TuringZhu
Copy link

@dyt123456 一个是上面 DankeBIBI 说的安装依赖, 一个是上面 Phyzait 说的修改浏览器列表

@XiangyiZhang
Copy link

直接用其模板,同样问题加,最新版本:v4.0.5。 image

image


同报错,m1芯片

@xixihhhh
Copy link

两种方法都试了,还是报错

@xixihhhh
Copy link

4.0.7还是报错

@yanlongqi
Copy link

4.0.7了,这个问题你们解决了没有,我也遇到了

@xixihhhh
Copy link

4.0.7了,这个问题你们解决了没有,我也遇到了

我退回到4.0.0-beta.82就不报错了,只能先用着,看看后面有没有啥解决方法

@DankeBIBI
Copy link
Author

4.0.7了,这个问题你们解决了没有,我也遇到了

没去关注了,之前公司搞个小程序想用这个框架的,后来报错就换了别的

@DankeBIBI DankeBIBI closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@DankeBIBI DankeBIBI reopened this Oct 29, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Mini Program Oct 29, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in Mini Program Oct 29, 2024
@TuringZhu
Copy link

4.0.7了,这个问题你们解决了没有,我也遇到了

没去关注了,之前公司搞个小程序想用这个框架的,后来报错就换了别的

你们换了uniapp还是什么

@xiaobc1234
Copy link

xiaobc1234 commented Nov 23, 2024

这个问题解决了吗? 4.0.7 依然遇到。 苹果m1


app.js错误:
 TypeError: taro.getDefaultExportFromCjs is not a function
    at isEmpty.js:77
    at WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1
    at _.runWith (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at q (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at n (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at taro.js:3
    at WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1
    at _.runWith (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at q (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at n (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)(env: macOS,mp,1.06.2409140; lib: 3.6.5)
TypeError: taro.getDefaultExportFromCjs is not a function
    at isEmpty.js:77
    at WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1
    at _.runWith (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at q (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at n (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at taro.js:3
    at WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1
    at _.runWith (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at q (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)
    at n (WASubContext.js?t=wechat&s=1732354869830&v=3.6.5:1)(env: macOS,mp,1.06.2409140; lib: 3.6.5)

@xiaobc1234
Copy link

从vite编译 切换到 webpack5 ,一切正常!

@BH4HPA
Copy link

BH4HPA commented Dec 3, 2024

macOS 15, M3 Pro 芯片,遇到同样的问题。

React+SCSS+TypeScript+NutUI

app.js错误:
 TypeError: taro.getDefaultExportFromCjs is not a function
    at VM2045 vendors.js:351
    at VM2015 WASubContext.js:1
    at _.runWith (VM2015 WASubContext.js:1)
    at q (VM2015 WASubContext.js:1)
    at n (VM2015 WASubContext.js:1)
    at VM2044 taro.js:3
    at VM2015 WASubContext.js:1
    at _.runWith (VM2015 WASubContext.js:1)
    at q (VM2015 WASubContext.js:1)
    at n (VM2015 WASubContext.js:1)(env: macOS,mp,1.06.2405020; lib: 3.7.0)
➜  linglong_app git:(main) ✗ yarn dev:weapp

> [email protected] build:weapp
> taro build --type weapp --watch

👽 Taro v4.0.8

Tips:
1. 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ NODE_ENV=production taro build --type weapp --watch


vite v4.5.5 building for production...

watching for file changes...

build started...
transforming (92) node_modules/@tarojs/runtime/dist/utils/cache.jsDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

More info: https://sass-lang.com/d/legacy-js-api

Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

More info: https://sass-lang.com/d/legacy-js-api

✓ 539 modules transformed.
dist/pages/index/index.wxml    0.08 kB
dist/pages/index/index.json    0.09 kB │ gzip:   0.11 kB
dist/comp.json                 0.11 kB │ gzip:   0.11 kB
dist/comp.wxml                 0.14 kB
dist/app.json                  0.22 kB │ gzip:   0.15 kB
dist/pages/index/index.wxss    0.40 kB
dist/utils.wxs                 1.00 kB
dist/vendors.wxss             43.92 kB
dist/base.wxml                56.21 kB
dist/comp.js                   0.16 kB │ gzip:   0.14 kB │ map:   0.41 kB
dist/app.js                    0.77 kB │ gzip:   0.46 kB │ map:   0.70 kB
dist/pages/index/index.js      1.95 kB │ gzip:   0.82 kB │ map:   2.79 kB
dist/vendors.js              155.07 kB │ gzip:  39.81 kB │ map: 324.64 kB
dist/taro.js                 445.95 kB │ gzip: 101.59 kB │ map: 744.31 kB
built in 5851ms.

@sephirothwzc
Copy link

taro 4.0.8 m1 使用 vite 依然报错,根据楼上 大哥的建议 切换使用 webpack 后 问题解决

@BYicon
Copy link

BYicon commented Dec 14, 2024

image

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
Status: In Progress
Development

No branches or pull requests