nuxt-modules / plausible

🎟️ Plausible Analytics integration for Nuxt
https://plausible.io
MIT License
106 stars 7 forks source link

Warning of duplicated imports "useTrackEvent" #32

Closed HADB closed 3 months ago

HADB commented 3 months ago
image
[10:18:37]  WARN  Duplicated imports "useTrackEvent", the one from "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/@nuxtjs+plausible@1.0.2_magicast@0.3.4_rollup@4.19.1/node_modules/@nuxtjs/plausible/dist/runtime/composables/useTrackEvent" has been ignored and "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/nuxt-gtag@2.1.0_magicast@0.3.4_rollup@4.19.1/node_modules/nuxt-gtag/dist/runtime/composables/useTrackEvent" is used

✔ Vite client built in 28ms                                                                                           10:18:38

[10:18:38]  WARN  Duplicated imports "useTrackEvent", the one from "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/@nuxtjs+plausible@1.0.2_magicast@0.3.4_rollup@4.19.1/node_modules/@nuxtjs/plausible/dist/runtime/composables/useTrackEvent" has been ignored and "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/nuxt-gtag@2.1.0_magicast@0.3.4_rollup@4.19.1/node_modules/nuxt-gtag/dist/runtime/composables/useTrackEvent" is used

✔ Vite server built in 1081ms                                                                                         10:18:39

[10:18:56]  WARN  Duplicated imports "useTrackEvent", the one from "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/@nuxtjs+plausible@1.0.2_magicast@0.3.4_rollup@4.19.1/node_modules/@nuxtjs/plausible/dist/runtime/composables/useTrackEvent" has been ignored and "/Users/bean/Projects/GitHub/HADB/hadb.me/node_modules/.pnpm/nuxt-gtag@2.1.0_magicast@0.3.4_rollup@4.19.1/node_modules/nuxt-gtag/dist/runtime/composables/useTrackEvent" is used
johannschopplich commented 3 months ago

Seems like an edge-case. Do you really need both @nuxtjs/plausible together with nuxt-gtag? And if so, so you have to use both useTrackEvent composables from each package?

HADB commented 3 months ago

I know @nuxtjs/plausible and nuxt-gtag are similar, but I use them both just to compare and choose which one to use. But I get these warnings just after configuring them in nuxt.config.ts without using any of the useTrackEvent composables.

HADB commented 3 months ago

Here is the minimal reproduction project: https://stackblitz.com/edit/nuxt-starter-xjk9z1?file=package.json,nuxt.config.ts

johannschopplich commented 3 months ago

You're right, the warnings only appear if you have actually configured to use both in the modules nuxt configuration. If you choose to compare, but only need one at build time, I'd recommend removing the other from your modules, as this will also reduce the bundle size.

In my opinion, this is intentional. Using both tracking libraries together feels like an edge case. Depending on which one is needed for manual event tracking, you can put the module that should provide the useTrackEvent composable at a higher position in the modules array.

Close this as not intended. This is only a warning and won't break your code. 🙂