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

fix: Cannot read property 'add' of undefined at onGlobalSetup #488

Closed
JoeyYoung1997 opened this issue May 24, 2021 · 7 comments
Closed

fix: Cannot read property 'add' of undefined at onGlobalSetup #488

JoeyYoung1997 opened this issue May 24, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@JoeyYoung1997
Copy link

🐛 The bug
What isn't working? Describe what the bug is.
I found out after debugger, "const onGlobalSetup =(fn)=> {globalSetup.add(fn);};", in this code, globalSetup has not yet been assigned in the globalPlugin function

code show as below:

export default ({ app, store }, inject) => {
onGlobalSetup(() => {
inject('navigateTo', func)
})
}

@JoeyYoung1997 JoeyYoung1997 added the bug Something isn't working label May 24, 2021
@danielroe
Copy link
Member

@JoeyYoung1997 Would you provide a reproduction? 🙏

Working example.

@danielroe danielroe added the needs-repro Waiting for code that can reproduce the issue label May 24, 2021 — with Volta.net
@negibouze
Copy link

I got the same error.
The following error is displayed on the browser console.

Chrome:

TypeError: Cannot read property 'add' of undefined
    at onGlobalSetup (index.mjs:459)

Firefox:

TypeError: globalSetup is undefined
    onGlobalSetup index.mjs:459

@josendf-basetis
Copy link

Same issue here,

client.js:102 TypeError: Cannot read property 'add' of undefined
    at onGlobalSetup (index.mjs:459)

While calling onGlobalSetup during a client plugin registration, seems that the variable globalSetup in the index.msj module has not been initialized:

let globalSetup;
const onGlobalSetup = (fn) => {
  globalSetup.add(fn);
};

Copy link
Member

Would you provide a reproduction so I can check this out?

@josendf-basetis
Copy link

Hi @danielroe,

Thank you for your prompt response, following is a reproduction:

https://codesandbox.io/s/goofy-night-t2sr6

The error occurs in plugin/someplugin.client.js

TypeError: Cannot read property 'add' of undefined

@danielroe danielroe removed the needs-repro Waiting for code that can reproduce the issue label May 25, 2021 — with Volta.net
@tobiasdiez
Copy link

Calling globalPlugin before works for me as a workaround:

import { provide, onGlobalSetup, globalPlugin } from '@nuxtjs/composition-api'

const myPlugin: Plugin = function (context, inject) {
  globalPlugin(context, inject)
  onGlobalSetup(() => {
    provide(...)
  })
}

@danielroe
Copy link
Member

This should be fixed in 0.24.1 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants