Skip to content

useShareAppMessage 等 React Hooks 在 Vite 构建时不可用 #18745

@franckchen

Description

@franckchen

请先确认

  • 我已搜索并确定这个提交不是重复的

Taro 版本

v4

相关领域

None

使用框架

React

相关平台

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 头条小程序
  • QQ 小程序
  • 钉钉小程序
  • 飞书小程序
  • 快手小程序

小程序基础库版本

No response

问题描述

在使用 Vite 构建 H5 应用时,useShareAppMessageuseShareTimeline 等 React hooks 无法正常使用,但在 Webpack 构建时工作正常。

复现链接

123

复现步骤

  1. 创建一个 Taro H5 项目,使用 Vite 作为编译器
  2. 在页面组件中使用 useShareAppMessage
import { useShareAppMessage } from '@tarojs/taro'

function Index() {
  useShareAppMessage(() => {
    return {
      title: '分享标题',
      path: '/pages/index/index'
    }
  })
  
  return <View>测试页面</View>
}
  1. 运行 npm run dev:h5npm run build:h5
  2. hook不会被正确出发

环境信息

👽 Taro v4.1.5

ℹ tailwindcss-patcher 绑定 Tailwind CSS -> node_modules/.pnpm/tailwindcss@3.4.17_ts-node@10.9.2_@swc+core@1.3.96_@types+node@24.3.1_typescript@5.9.3_/node_modules/tailwindcss (v3.4.17)                                      9:40:30 AM
✔ 当前使用 Tailwind CSS 版本为: 3.4.17                                                                                                                                                                                        9:40:30 AM

  Taro CLI 4.1.5 environment info:
    System:
      OS: macOS 26.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 25.2.1 - ~/.local/state/fnm_multishells/3959_1768179927517/bin/node
      npm: 11.7.0 - ~/.local/state/fnm_multishells/3959_1768179927517/bin/npm
    npmPackages:
      @tarojs/cli: 4.1.5 => 4.1.5 
      @tarojs/components: 4.1.5 => 4.1.5 
      @tarojs/helper: 4.1.5 => 4.1.5 
      @tarojs/plugin-framework-react: 4.1.5 => 4.1.5 
      @tarojs/plugin-html: 4.1.5 => 4.1.5 
      @tarojs/plugin-http: 4.1.5 => 4.1.5 
      @tarojs/plugin-platform-h5: 4.1.5 => 4.1.5 
      @tarojs/plugin-platform-weapp: 4.1.5 => 4.1.5 
      @tarojs/react: 4.1.5 => 4.1.5 
      @tarojs/runtime: 4.1.5 => 4.1.5 
      @tarojs/shared: 4.1.5 => 4.1.5 
      @tarojs/taro: 4.1.5 => 4.1.5 
      @tarojs/taro-loader: 4.1.5 => 4.1.5 
      @tarojs/vite-runner: 4.1.5 => 4.1.5 
      babel-preset-taro: 4.1.5 => 4.1.5 
      react: ^18.3.1 => 18.3.1

开源贡献

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-reactFramework - ReactT-weappTarget - 编译到微信小程序V-4Version - 4.xbugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions