Skip to content

Commit f92fa92

Browse files
committed
fix: resolve module error due to incorrect bundling
1 parent a43e76a commit f92fa92

File tree

4 files changed

+188
-176
lines changed

4 files changed

+188
-176
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"build:package": "turbo run build --filter=@simpleanalytics/nuxt",
77
"postinstall": "turbo run postinstall",
88
"dev:prepare": "turbo run dev:prepare --filter=@simpleanalytics/nuxt",
9+
"pack:package": "pnpm pack --filter=@simpleanalytics/nuxt",
910
"lint": "turbo run lint",
1011
"format": "prettier --write \"**/*.{ts,tsx,md}\""
1112
},
1213
"devDependencies": {
1314
"@changesets/cli": "^2.29.5",
1415
"turbo": "^2.5.5"
1516
},
16-
"packageManager": "pnpm@9.15.0"
17+
"packageManager": "pnpm@10.15.1"
1718
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { useRuntimeConfig } from "#imports";
22
import { defineNuxtPlugin } from "nuxt/app";
33

4-
import SimpleAnalytics from "simple-analytics-vue";
4+
/* @ts-expect-error -- force ES module import */
5+
import SimpleAnalytics from "simple-analytics-vue/dist/index.mjs";
6+
import type { SimpleAnalyticsOptions } from "simple-analytics-vue";
7+
import type { App, Plugin } from "vue";
8+
9+
type SimpleAnalyticsPlugin = Plugin & {
10+
install(app: App, options?: SimpleAnalyticsOptions): void;
11+
};
512

613
export default defineNuxtPlugin((nuxtApp) => {
714
const config = useRuntimeConfig();
815

9-
nuxtApp.vueApp.use(SimpleAnalytics, {
10-
skip: !config.public.simpleAnalytics.enabled,
16+
// We have to cast the plugin here because the forced .mjs import
17+
nuxtApp.vueApp.use(SimpleAnalytics as SimpleAnalyticsPlugin, {
18+
skip: config.public.simpleAnalytics.enabled === false,
1119
domain: config.public.simpleAnalytics.domain,
1220
});
1321
});

packages/nuxt/types.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export {};
22

33
declare module "@nuxt/schema" {
4+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
45
interface RuntimeConfig {
56
// Private runtime config (server-side only)
67
}
@@ -94,3 +95,9 @@ declare global {
9495
): void;
9596
}
9697
}
98+
99+
declare module "@vue/runtime-core" {
100+
interface InjectionKeys {
101+
saEvent: (event: string) => void;
102+
}
103+
}

0 commit comments

Comments
 (0)