Skip to content

bug: Vue toast Uncaught TypeError: Cannot set properties of undefined (setting '$lazyInstance$') #24503

@wilhantian

Description

@wilhantian

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

An error will be reported when toast is created in an external ts file:

Uncaught TypeError: Cannot set properties of undefined (setting '$lazyInstance$')
    at registerInstance (index-06cd27b1.js?cd96:4)
    at new t (overlays-5f2f4ffc.js?9cdf:4)
    at eval (overlays-5f2f4ffc.js?9cdf:4)
    at async toast (toast.ts?e2e3:4)
registerInstance @ index-06cd27b1.js?cd96:4
t @ overlays-5f2f4ffc.js?9cdf:4
eval @ overlays-5f2f4ffc.js?9cdf:4
Promise.then (async)
createOverlay @ overlays-5f2f4ffc.js?9cdf:4
create @ overlays-5f2f4ffc.js?9cdf:4
toast @ toast.ts?e2e3:4
exeHandler @ index.vue?d776:71
exeHandler @ index.vue?b665:33
eval @ runtime-dom.esm-bundler.js?2725:371
callWithErrorHandling @ runtime-core.esm-bundler.js?d2dd:6737
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js?d2dd:6746
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js?d2dd:6756
invoker @ runtime-dom.esm-bundler.js?2725:357
toast.ts?e2e3:11 Uncaught (in promise) TypeError: t.present is not a function
    at toast (toast.ts?e2e3:11)

Expected Behavior

It can run normally like ionic 5.x

Steps to Reproduce

src/toast.ts

async function toast(){
    const t = await toastController.create({
        message: 'hello'
    });
    t.present();
}

src/*.vue

import toast from './toast';

defineComponent({
    setup(){
        onMounted(()=>{
            toast(); // Uncaught TypeError: Cannot set properties of undefined (setting '$lazyInstance$')
        });
    }
})

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/vue 6.0.1

Capacitor:

Capacitor CLI : 3.3.3
@capacitor/android : not installed
@capacitor/core : 3.3.3
@capacitor/ios : not installed

Utility:

cordova-res : 0.15.4
native-run : 1.5.0

System:

NodeJS : v14.15.0 (/usr/local/bin/node)
npm : 6.14.8
OS : macOS Monterey

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions