nuxt-gtm icon indicating copy to clipboard operation
nuxt-gtm copied to clipboard

useGtm() is randomly undefined

Open realconvis opened this issue 2 years ago • 6 comments
trafficstars

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 avatar Oct 10 '23 07:10 realconvis

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?

realconvis avatar Oct 10 '23 08:10 realconvis

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

FilipEIG avatar Oct 20 '23 13:10 FilipEIG

I got the same issue.

MooseSaeed avatar Oct 20 '23 22:10 MooseSaeed

I got the same issue. nuxt version: 3.2.3

bibirock avatar Nov 10 '23 08:11 bibirock

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

marcel-wtfoxtrot avatar Jan 12 '24 11:01 marcel-wtfoxtrot

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: https://github.com/gtm-support/vue-gtm/pull/409

filiphazardous avatar Feb 07 '24 08:02 filiphazardous