vue-gtm: Bug: Vue Router required by Vue GTM when its not even passed into the options

Info

Tool Version
Plugin v3.4.1
Vue v3.0.0
Node v14.14.0
OS linux & mac

Input

	app.use(createGtm({
		id: 'GTM-FOO',
		defer: true,
		enabled: false,
		debug: process.env.NODE_ENV === 'development',
		loadScript: true,
		trackOnNextTick: false
	}));

Output or Error

while building for production with webpack:

    ERROR in ../node_modules/vue-gtm/dist/index.js
    Module not found: Error: Can't resolve 'vue-router' in '/Users/foo-user/workspace/bar-project/node_modules/vue-gtm/dist'
     @ ../node_modules/vue-gtm/dist/index.js 162:85-106
     @ ./js/main.js

Expected Output

No error.

Additional Context

I am using vue-gtm in multipage project where vue-router isnt needed, but vue gtm still complains that vue-router int installed when building for production. I think it might relate to the fact that you use the import('vue-router') statement in your code (https://github.com/mib200/vue-gtm/blob/0a3691bc53b77d1e02de4040bec177346dc2f990/src/index.ts#L101).

I dont know how to fix this behavior, the last working version in my env is 3.1.1. Maybe specificing vue router as peer dep could help?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15

Most upvoted comments

https://github.com/mib200/vue-gtm/issues/122#issuecomment-793923232

Having this in my webpack config actually works:

    externals: {
        'vue-router': 'require("vue-router")'
    }

but tbh i find it a bit annoying to manually do that in my webpack config to work with a 3rd party package

Hi! Sorry, yes i’ll take a look at this later okay? Thanks for working on this so quickly!