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

[bug] getStorageSync is not a function in TypeScript 5, PNPM 8 & webpack 5.77 #13586

Closed
TechQuery opened this issue Apr 5, 2023 · 10 comments · Fixed by #13596
Closed

[bug] getStorageSync is not a function in TypeScript 5, PNPM 8 & webpack 5.77 #13586

TechQuery opened this issue Apr 5, 2023 · 10 comments · Fixed by #13596
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@TechQuery
Copy link

TechQuery commented Apr 5, 2023

相关平台

H5

复现仓库

idea2app/Taro-Vant-MobX-ts#6

  • 浏览器版本: Chrome 111.0.5563.147
  • 使用框架: React

复现步骤

pnpm dev h5 启动后,点 demo 主导航栏最后一个图标,代码会执行

import { getStorageSync } from '@tarojs/taro';

getStorageSync('token');

期望结果

没有报错,让接口逻辑可以正常执行。

实际结果

Uncaught (in promise) TypeError: _tarojs_taro__WEBPACK_IMPORTED_MODULE_7___default(...).getStorageSync is not a function

环境信息

👽 Taro v3.6.4


  Taro CLI 3.6.4 environment info:
    System:
      OS: Windows 10 10.0.19045
    Binaries:
      Node: 16.19.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.19 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
      npm: 9.6.3 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.4 => 3.6.4
      @tarojs/components: 3.6.4 => 3.6.4
      @tarojs/helper: 3.6.4 => 3.6.4
      @tarojs/plugin-framework-react: 3.6.4 => 3.6.4
      @tarojs/plugin-html: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-alipay: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-h5: ^3.6.4 => 3.6.4
      @tarojs/plugin-platform-jd: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-qq: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-swan: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-tt: 3.6.4 => 3.6.4
      @tarojs/plugin-platform-weapp: 3.6.4 => 3.6.4
      @tarojs/runtime: 3.6.4 => 3.6.4
      @tarojs/shared: 3.6.4 => 3.6.4
      @tarojs/taro: 3.6.4 => 3.6.4
      @tarojs/webpack5-runner: 3.6.4 => 3.6.4
      babel-preset-taro: 3.6.4 => 3.6.4
      eslint-config-taro: 3.6.4 => 3.6.4

补充信息

运行时 import 的对象与此相同:#12943 (comment)

@YujiaCheng1996
Copy link

vue3版本有同样的问题,Taro.request、Taro.getSystemInfo啥的也是提示这个未找到。同时vue-router也不能用了,打开路径变为/#/pages/index/index,3.6.2版本没有这个尾巴。

@ZakaryCode ZakaryCode added V-3 Version - 3.x F-react Framework - React T-h5 Target - 编译到 H5 labels Apr 6, 2023
@naico-wang

This comment was marked as off-topic.

@ZakaryCode
Copy link
Contributor

babel 插件导出 API 缺失错误,可通过以下方法临时修复

  h5: {
    webpackChain (chain) {
      const rules = chain.module.rules
      const script = rules.get('script')
      const babelLoader = script.uses.get('babelLoader')
      babelLoader.set('options', {
        ...babelLoader.get('options'),
        plugins: [
          [require('babel-plugin-transform-taroapi'), {
            packageName: '@tarojs/taro',
            // https://unpkg.com/browse/@tarojs/plugin-platform-h5@3.6.2/dist/taroApis.js
            apis: require('./taroApis')
          }]
        ]
      })
    }
  }

@ZakaryCode

This comment was marked as off-topic.

@naico-wang

This comment was marked as off-topic.

xuanzebin pushed a commit that referenced this issue Apr 7, 2023
* fix(h5): 修复 h5 依赖导出失败问题 fix #13586

* chore(devs): 补充缺失依赖 fix #13572

* test(snapshot): 更新快照

* test(snapshot): 更新快照

---------

Co-authored-by: zhutianjian <zhutianjian@SZMAC-XYH1GJ72.local>
Co-authored-by: xuanzebin <xuanzebin3@jd.com>
@ZakaryCode ZakaryCode moved this to Padding in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
@ZakaryCode ZakaryCode moved this from Padding to Done in H5 Apr 10, 2023
@axetroy
Copy link

axetroy commented Jun 30, 2023

3.6.9-aplha.6 依旧存在这个问题

楼上的方法不管用,而且

// https://unpkg.com/browse/@tarojs/plugin-platform-h5@3.6.2/dist/taroApis.js

这个文件从 3.6.8 开始就消失了,不见了,搜索整个 node_modules/@tarojs 目录都找不到

@ShaoXuChenTTT
Copy link

ShaoXuChenTTT commented Aug 8, 2023

同楼上,目前其他npm包引用的内容有比较好的转化方法吗,
(https://github.com/NervJS/taro/blob/next/packages/babel-plugin-transform-taroapi/src/index.ts#L47) apis入参已经没办法获取了
@ZakaryCode

@wikiwikiki
Copy link

image
直接引用getStorageSync方法 是可以的,Taro.getStorageSync 是undefined

@QuincyX
Copy link

QuincyX commented Aug 8, 2024

4.0.4 依然有这个问题

@yx-design
Copy link

import {getStorageSync} from "@tarojs/taro";

const getCookie = (k: string): string => {
return getStorageSync("")
};

4.0.4版本,Cannot resolve symbol 'getStorageSync' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

9 participants