NervJS / taro

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

taro init react js project, 使用taro开发的组件,H5环境报错 i.getStorageSync is not a function #9938

Closed wkh2 closed 1 year ago

wkh2 commented 3 years ago

相关平台

微信小程序

复现仓库

https://git.jd.com/wanghui278/apl-taro-nbyh.git 小程序基础库: Google Chrome Google Chrome 已是最新版本 版本 92.0.4515.107(正式版本) (x86_64) 使用框架: React

复现步骤

解压demo 执行 ➜ rm -rf node_modules package-lock.json
然后执行 npm i npm run dev:h5 即可复现

期望结果

页面正常渲染,无报错

实际结果

页面有报错 Uncaught TypeError: i.getStorageSync is not a function at c.value (index.umd.js?c52c:1) at callComponentWillMount (react-dom.development.js?61bb:12784) at mountClassInstance (react-dom.development.js?61bb:12878) at updateClassComponent (react-dom.development.js?61bb:17426) at beginWork (react-dom.development.js?61bb:19073) at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945) at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994) at invokeGuardedCallback (react-dom.development.js?61bb:4056) at beginWork$1 (react-dom.development.js?61bb:23964) at performUnitOfWork (react-dom.development.js?61bb:22776)

index.umd.js?c52c:1 Uncaught TypeError: i.getStorageSync is not a function at c.value (index.umd.js?c52c:1) at callComponentWillMount (react-dom.development.js?61bb:12784) at mountClassInstance (react-dom.development.js?61bb:12878) at updateClassComponent (react-dom.development.js?61bb:17426) at beginWork (react-dom.development.js?61bb:19073) at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945) at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994) at invokeGuardedCallback (react-dom.development.js?61bb:4056) at beginWork$1 (react-dom.development.js?61bb:23964) at performUnitOfWork (react-dom.development.js?61bb:22776) react-dom.development.js?61bb:20085 The above error occurred in the component:

at c (webpack-internal:///./node_modules/@xnfe/apl-dynamic-layout/dist/index.umd.js:4127:14)
at n (webpack-internal:///./node_modules/@xnfe/apl-product-detail/dist/index.umd.js:813:14)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at n (webpack-internal:///./node_modules/@xnfe/apl-product-detail/dist/index.umd.js:7264:14)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at n (webpack-internal:///./node_modules/@xnfe/apl-product-detail/dist/index.umd.js:1202:14)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at n (webpack-internal:///./node_modules/@xnfe/apl-product-detail/dist/index.umd.js:7304:14)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at i (webpack-internal:///./node_modules/@xnfe/apl-product-detail/dist/index.umd.js:7513:14)
at taro-view-core
at Index (webpack-internal:///./node_modules/@tarojs/components/dist-h5/react/utils/reactify-wc.js:183:83)
at Index (webpack-internal:///./src/pages/index/index.jsx:37:147)

环境信息

 Taro v3.3.1

  Taro CLI 3.3.1 environment info:
    System:
      OS: macOS High Sierra 10.13.6
      Shell: 5.7 - /usr/local/bin/zsh
    Binaries:
      Node: 10.15.2 - ~/.nvm/versions/node/v10.15.2/bin/node
      Yarn: 1.19.1 - ~/.yarn/bin/yarn
      npm: 6.14.4 - ~/.nvm/versions/node/v10.15.2/bin/npm
    npmPackages:
      @tarojs/components: 3.3.1 => 3.3.1 
      @tarojs/mini-runner: 3.3.1 => 3.3.1 
      @tarojs/react: 3.3.1 => 3.3.1 
      @tarojs/runtime: 3.3.1 => 3.3.1 
      @tarojs/taro: 3.3.1 => 3.3.1 
      @tarojs/webpack-runner: 3.3.1 => 3.3.1 
      babel-preset-taro: 3.3.1 => 3.3.1 
      eslint-config-taro: 3.3.1 => 3.3.1 
      react: ^17.0.0 => 17.0.2 
    npmGlobalPackages:
      typescript: 4.0.2
Chlzm commented 3 years ago

兼容性问题,import {getStorageSync} from '@tarojs/taro' 即可解决,不要使用import Taro from '@tarojs/taro'.,Taro. getStorageSync. 希望能帮到你

AaronDaiR commented 1 year ago

哥,还是有问题啊,都2023年了 还没解决吗。。

AaronDaiR commented 1 year ago

import {getStorageSync} from '@tarojs/taro-h5'可以; 但是Taro本身就是一个跨端编译的框架,这样搞不是坑吗。。 import {getStorageSync} from '@tarojs/taro' 就不行。