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

Cannot set property '$gtm' of undefined => Use vue-gtm: 3.0.0-vue2 without ~ or ^ #98

Closed
popovdk opened this issue Sep 29, 2020 · 22 comments

Comments

@popovdk
Copy link

popovdk commented Sep 29, 2020

When connecting to an application on Vue 2, an error occurs Uncaught TypeError: Cannot set property '$ gtm' of undefined due to the fact that the plugin is connected via Vue.config.globalProperties, and this is possible only in Vue 3

Installed simply through npm without specifying additional tags

@Shinigami92
Copy link
Collaborator

Please use the vue-2 version of the plugin

@Shinigami92
Copy link
Collaborator

@popovdk Please close this issue if this fixed your problem 🙂

@bastianaf
Copy link

same issue here. This is my config

Vue.use(VueGtm, { id: 'GTM-SECRET', defer: false, enabled: true, debug: true, loadScript: true, trackOnNextTick: false, })

and got

image
image

@Shinigami92
Copy link
Collaborator

Shinigami92 commented Sep 29, 2020

What do you have in your package.json?

Please try

{
  ...
  "dependencies": {
    ...
    "vue-gtm": "3.0.0-vue2"
  }
}

without ~ or ^
Then remove node_modules and reinstall

If you are using ~ or ^ and not the exact version you may fallback to the latest version, and this is the vue 3 branch ⚠️


I can confirm that 3.0.0-vue2 is really the vue2 branch: https://unpkg.com/[email protected]/dist/index.js

@bastianaf
Copy link

What do you have in your package.json?

Please try

{
  ...
  "dependencies": {
    ...
    "vue-gtm": "3.0.0-vue2"
  }
}

without ~ or ^
Then remove node_modules and reinstall

If you are using ~ or ^ and not the exact version you may fallback to the latest version, and this is the vue 3 branch ⚠️

I can confirm that 3.0.0-vue2 is really the vue2 branch: https://unpkg.com/[email protected]/dist/index.js

this works for me, thanks a lot

@Shinigami92 Shinigami92 changed the title Bug: Uncaught TypeError: Cannot set property '$gtm' of undefined Cannot set property '$gtm' of undefined => Use vue-gtm: 3.0.0-vue2 without ~ or ^ Oct 1, 2020
@Shinigami92 Shinigami92 pinned this issue Oct 1, 2020
@popovdk popovdk closed this as completed Oct 1, 2020
@mbence
Copy link

mbence commented Oct 2, 2020

Sorry guys, I'm a little confused:
3.0.0-vue2...3.0.0

Anyway, I still get main.js?56d7:50 Uncaught TypeError: vue_gtm__WEBPACK_IMPORTED_MODULE_18___default(...) is not a function with Vue 2 and

    "vue-gtm": "3.0.0-vue2",

@Shinigami92
Copy link
Collaborator

  • 3.0.0 is for vue 3
  • 3.0.0-vue2 is for vue 2

also please clear your node_modules and perform npm or yarn install again

@wagslane
Copy link

wagslane commented Oct 4, 2020

Can the requirement 3.0.0-vue2 be added to the docs?

@Shinigami92
Copy link
Collaborator

Sure, if you want you can open a PR :)
If not, I think I will add it tomorrow or so

@Shinigami92
Copy link
Collaborator

@lane-c-wagner Added 6f15774

@AndrewBogdanovTSS
Copy link

Is there any way to protect a use of ^ for -vue2 version? Right now it's very confusing behavior

@Shinigami92
Copy link
Collaborator

If you know a strategy, please let me know!
I'm not well into npm publishing

@AndrewBogdanovTSS
Copy link

AndrewBogdanovTSS commented Oct 8, 2020

@Shinigami92 you need to create 2 different packages for each project, that's the most common-sense solution. Plus your issues for different Vue versions won't mix up and it will all look more organized this way. I guess you can even use a package namespace, something similar to vue or nuxt is doing. e.g. @vue-gtm/vue-2 @vue-gtm/vue-3

@Shinigami92
Copy link
Collaborator

For doing so, I need permission by the license owner @mib200
This is not my repo. If he give me permission to transfer everything to me or create an organization structure (in npm and github) and provide admin access, I can do it.

Currently I even don't have permission to protect the vue-2 branch ^^'

@cartok
Copy link
Contributor

cartok commented Nov 3, 2020

Can this be solved in a more generic way, so you would not need that additional layer?

@cartok
Copy link
Contributor

cartok commented Nov 3, 2020

What do you think about checking the vue version and depending on the result import() the code you need guys?

@Shinigami92
Copy link
Collaborator

Without breaking TypeScript support? I don't think so.

If you have time to experiment with it, creating compatibility for Vue 2 and Vue 3 together, feel free to do so 🙂

But in the (very) long-term this is irrelevant, as support for Vue 2 will one day be discontinued

@antoci-alin
Copy link

I'm also interested in a cleaner approach for this versioning.

@KhozmoS
Copy link

KhozmoS commented Dec 18, 2020

Hi guys, why dont put on the README.MD this important info:
Cannot set property '$gtm' of undefined => Use vue-gtm: 3.0.0-vue2 without ~ or ^
#98

@Shinigami92
Copy link
Collaborator

Shinigami92 commented Dec 18, 2020

@KhozmoS ... it is on the readme...

Oh, and beside that it's already there: this is an Open Source project, so you can create PRs for it, also for README.md
So if you miss anything, feel free and I will make a review and merge it

@KhozmoS
Copy link

KhozmoS commented Dec 18, 2020

@Shinigami92 really don't know how I didn't see that... my bad 👌

@Shinigami92
Copy link
Collaborator

We could try https://github.com/vueuse/vue-demi 🤔

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

9 participants