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

useGtm() is randomly undefined #14

Open
realconvis opened this issue Oct 10, 2023 · 6 comments
Open

useGtm() is randomly undefined #14

realconvis opened this issue Oct 10, 2023 · 6 comments

Comments

@realconvis
Copy link

The GTM snippet is always loaded and the TrackView Event via router sync is always fired.

But I have the problem, that useGtm() inside vue components is randomly undefined.

If I stop and start the development server (npm run dev) several times or clear the cache (npx nuxi cleanup), it eventually works again.
When I then restart the development server again later, it doesn't work again.

What could be the problem.

@realconvis
Copy link
Author

Now I've figured out how to reproduce the error explicitly.
The error occurs whenever I run the "npx nuxi cleanup" command before the "npx nuxi dev". If I then stop and start the dev server without running the cleanup first, useGtm() is no longer undefined. Only when I run the cleanup again and start the dev server for the first time, useGtm() is undefined again. What could be the reason for this?

@FilipEIG
Copy link

FilipEIG commented Oct 20, 2023

Having same issue. Appears to be an issue only in dev environment though.

@MooseSaeed
Copy link

I got the same issue.

@bibirock
Copy link

I got the same issue.
nuxt version: 3.2.3

@marcel-wtfoxtrot
Copy link

Same here with Nuxt 3.9. Any way to resovle this?

@filiphazardous
Copy link

It seems Vite does something unexpected when minifying code. (For me, it copied the useGtm function instead of importing it, but useGtm was relying on a locally scoped variable.)
This PR upstream attempts to solve the problem: gtm-support/vue-gtm#409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants