Skip to content

🐛 [Bug]: 无法在小程序启动时调用Toast loading #989

@Duo-Huang

Description

@Duo-Huang

问题出在哪个包

@taroify/core

正在使用的 Taroify 版本是多少

0.9.0

问题出在哪个平台/设备/浏览器

weapp

重现链接

https://codesandbox.io/p/sandbox/dark-shape-ms26md?file=%2Fsrc%2Fapp.ts%3A19%2C24

环境信息

╰─ taro info ─╯
👽 Taro v4.1.7

last commit---- 6a1aa1b
Current build env is: undefined
Current node env is: undefined

Taro CLI 4.1.7 environment info:
System:
OS: macOS 26.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.11.0 - /Users/duohuang/.asdf/installs/nodejs/24.11.0/bin/node
npm: 11.6.1 - /Users/duohuang/.asdf/plugins/nodejs/shims/npm
npmPackages:
@tarojs/cli: 4.1.7 => 4.1.7
@tarojs/components: ^4.1.8 => 4.1.8
@tarojs/helper: 4.1.7 => 4.1.7
@tarojs/plugin-framework-react: 4.1.7 => 4.1.7
@tarojs/plugin-platform-alipay: 4.1.7 => 4.1.7
@tarojs/plugin-platform-h5: 4.1.7 => 4.1.7
@tarojs/plugin-platform-harmony-hybrid: 4.1.7 => 4.1.7
@tarojs/plugin-platform-jd: 4.1.7 => 4.1.7
@tarojs/plugin-platform-qq: 4.1.7 => 4.1.7
@tarojs/plugin-platform-swan: 4.1.7 => 4.1.7
@tarojs/plugin-platform-tt: 4.1.7 => 4.1.7
@tarojs/plugin-platform-weapp: 4.1.7 => 4.1.7
@tarojs/react: 4.1.7 => 4.1.7
@tarojs/runtime: 4.1.7 => 4.1.7
@tarojs/shared: 4.1.7 => 4.1.7
@tarojs/taro: 4.1.7 => 4.1.7
@tarojs/taro-loader: 4.1.7 => 4.1.7
@tarojs/webpack5-runner: 4.1.7 => 4.1.7
babel-preset-taro: 4.1.7 => 4.1.7
eslint-config-taro: 4.1.7 => 4.1.7
react: ^18.0.0 => 18.3.1

重现步骤

启动小程序, 报错如下

TypeError: Cannot read property '$taroPath' of undefined
    at getPagePath (._node_modules_.pnpm_@[email protected]_@[email protected]_@[email protected]_@[email protected]__b1dd2c742dbfe85b019241bf717f4bfc_node_modules_@taroify_core_utils_dom_portal.js:7)
    at openToast (._node_modules_.pnpm_@[email protected]_@[email protected]_@[email protected]_@[email protected]__b1dd2c742dbfe85b019241bf717f4bfc_node_modules_@taroify_core_toast_toast.imperative.js:40)
    at Function.loading (._node_modules_.pnpm_@[email protected]_@[email protected]_@[email protected]_@[email protected]__b1dd2c742dbfe85b019241bf717f4bfc_node_modules_@taroify_core_toast_toast.imperative.js:68)
    at Object.showLoading (._src_utils_messager.ts:16)
    at Object.current (._src_app.ts:51)
    at callback (vendors-node_modules_taro_weapp_prebundle_tarojs_plugin-framework-react_dist_runtime_js.js?t=wechat&s=1762832736573&v=eac71047e2a36b836229a7b0064290a3:98)
    at vendors-node_modules_taro_weapp_prebundle_tarojs_plugin-framework-react_dist_runtime_js.js?t=wechat&s=1762832736573&v=eac71047e2a36b836229a7b0064290a3:464
    at Array.forEach (<anonymous>)
    at triggerAppHook (vendors-node_modules_taro_weapp_prebundle_tarojs_plugin-framework-react_dist_runtime_js.js?t=wechat&s=1762832736573&v=eac71047e2a36b836229a7b0064290a3:464)
    at onLaunch (vendors-node_modules_taro_weapp_prebundle_tarojs_plugin-framework-react_dist_runtime_js.js?t=wechat&s=1762832736573&v=eac71047e2a36b836229a7b0064290a3:393)(env: macOS,mp,1.06.2504060; lib: 3.8.12)

你知道如何解决这个问题吗

No

您是否愿意参与修复这个问题,并创建一个 PR

None

修复这个问题的解决方案

因为小程序onlaunch时page还没生成 , 但是toast组件需要调用getCurrentPages访问页面堆栈,

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions