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

createAsyncThunk创建的action无法使用dispatch #15517

Open
hikzhang opened this issue Apr 16, 2024 · 2 comments
Open

createAsyncThunk创建的action无法使用dispatch #15517

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

Comments

@hikzhang
Copy link

相关平台

微信小程序

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

复现步骤

  1. 在slice中定义foo = createAsyncThunk(...),并在createSlice的extrareducers中使用build.addCase(foo.pending...)等
  2. 在页面中使用dispatch(foo)

期望结果

foo定义的async functionf

实际结果

执行时报错:AbortController is not defined

ReferenceError: AbortController is not defined
    at vendors-node_modules_taro_weapp_prebundle_reduxjs_toolkit_js.js?t=wechat&s=1713083731279&v=c3009756f740784f3e1fbc8afa686d9b:2359
    at vendors-node_modules_taro_weapp_prebundle_reduxjs_toolkit_js.js?t=wechat&s=1713083731279&v=c3009756f740784f3e1fbc8afa686d9b:1525
    at vendors-node_modules_taro_weapp_prebundle_reduxjs_toolkit_js.js?t=wechat&s=1713083731279&v=c3009756f740784f3e1fbc8afa686d9b:1790
    at vendors-node_modules_taro_weapp_prebundle_reduxjs_toolkit_js.js?t=wechat&s=1713083731279&v=c3009756f740784f3e1fbc8afa686d9b:1614
    at Object.current (index.tsx?cf8d:13)
    at Object.callback (vendors-node_modules_taro_weapp_prebundle_tarojs_plugin-framework-react_dist_runtime_js.js?t=wechat&s=1713083731279&v=dc9330fe3530ade2dc87a23f82bc3b47:96)
    at vendors-node_modules_taro_weapp_prebundle_chunk-H5CKLZB7_js.js?t=wechat&s=1713083731279&v=1f79f6e1c526573bda1897e0aa961ea9:1131
    at Array.map (<anonymous>)
    at safeExecute (vendors-node_modules_taro_weapp_prebundle_chunk-H5CKLZB7_js.js?t=wechat&s=1713083731279&v=1f79f6e1c526573bda1897e0aa961ea9:1131)
    at AppWrapper.<anonymous> (vendors-node_modules_taro_weapp_prebundle_chunk-H5CKLZB7_js.js?t=wechat&s=1713083731279&v=1f79f6e1c526573bda1897e0aa961ea9:1209)(env: macOS,mp,1.06.2402040; lib: 3.4.1)

环境信息

taro info
👽 Taro v3.6.26

(node:65681) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

  Taro CLI 3.6.26 environment info:
    System:
      OS: macOS 14.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 21.7.2 - /opt/homebrew/bin/node
      npm: 10.5.0 - /opt/homebrew/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.26 => 3.6.26
      @tarojs/components: 3.6.26 => 3.6.26
      @tarojs/helper: 3.6.26 => 3.6.26
      @tarojs/plugin-framework-react: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-alipay: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-h5: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-jd: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-qq: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-swan: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-tt: 3.6.26 => 3.6.26
      @tarojs/plugin-platform-weapp: 3.6.26 => 3.6.26
      @tarojs/react: 3.6.26 => 3.6.26
      @tarojs/runtime: 3.6.26 => 3.6.26
      @tarojs/shared: 3.6.26 => 3.6.26
      @tarojs/taro: 3.6.26 => 3.6.26
      @tarojs/taro-loader: 3.6.26 => 3.6.26
      @tarojs/webpack5-runner: 3.6.26 => 3.6.26
      babel-preset-taro: 3.6.26 => 3.6.26
      eslint-config-taro: 3.6.26 => 3.6.26
      react: ^18.0.0 => 18.2.0

补充信息

实际taro版本是3.6.26(无可选项)

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Apr 16, 2024
This was referenced Apr 20, 2024
@seekerliu
Copy link

解决方法:
1,安装这俩包:yet-another-abortcontroller-polyfill,event-target-polyfill
2,app.js import:
import 'event-target-polyfill';
import 'yet-another-abortcontroller-polyfill';

@hikzhang
Copy link
Author

感谢!按你的解决方法成功运行了。

不过是否应该从Taro框架本身引入才更好呢。

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: Todo
Development

No branches or pull requests

2 participants