NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/

Home Page:https://docs.taro.zone/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

swr 在 dev 下正常。build 后则出现了 TypeError: Cannot read property 'useContext' of null

LengYXin opened this issue · comments

相关平台

微信小程序

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

复现步骤

随意找个组件使用 useSWR 或者 SWRConfig 就行。
<SWRConfig
// https://swr.bootcss.com/docs/api
value={{ revalidateOnFocus: false }}
>

期望结果

执行build 后正常

实际结果

执行build后
TypeError: Cannot read property 'useContext' of null
at define.push.../../node_modules/react/cjs/react.production.min.js.exports.useContext (vendors.js?t=wechat&s=1718764236515&v=3ba68365142b07947f0be04c33d77cf3:37)
at SWRConfig (vendors.js?t=wechat&s=1718764236515&v=3ba68365142b07947f0be04c33d77cf3:635)
image
image

环境信息

Taro CLI 3.6.32 environment info:
    System:
      OS: macOS 14.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
      Yarn: 1.22.22 - ~/.nvm/versions/node/v20.14.0/bin/yarn
      npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.32 => 3.6.32 
      @tarojs/components: 3.6.32 => 3.6.32 
      @tarojs/helper: 3.6.32 => 3.6.32 
      @tarojs/plugin-framework-react: 3.6.32 => 3.6.32 
      @tarojs/plugin-html: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-alipay: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-h5: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-jd: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-qq: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-swan: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-tt: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-weapp: 3.6.32 => 3.6.32 
      @tarojs/react: 3.6.32 => 3.6.32 
      @tarojs/runtime: 3.6.32 => 3.6.32 
      @tarojs/shared: 3.6.32 => 3.6.32 
      @tarojs/taro: 3.6.32 => 3.6.32 
      @tarojs/taro-loader: 3.6.32 => 3.6.32 
      @tarojs/webpack5-runner: 3.6.32 => 3.6.32 
      babel-preset-taro: 3.6.32 => 3.6.32 
      react: ^18 => 18.3.1 

遇到相同问题