From 94d7c907d89e977928f9838b3de7c8af016428a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Mon, 3 Apr 2023 03:16:11 -0700 Subject: [PATCH] fix: resolve aliases relative to module's dir (#548) --- src/module.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/module.ts b/src/module.ts index fbd87e27..5a9e1503 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,3 +1,4 @@ +import { fileURLToPath } from 'url' import { defu } from 'defu' import { resolvePath } from 'mlly' import type { SentryCliPluginOptions } from '@sentry/webpack-plugin' @@ -13,6 +14,8 @@ export type { ModuleOptions, ModulePublicRuntimeConfig } const logger = useLogger('nuxt:sentry') +const moduleDir = fileURLToPath(new URL('./', import.meta.url)) + export default defineNuxtModule({ meta: { name: '@nuxtjs/sentry', @@ -94,9 +97,9 @@ export default defineNuxtModule({ ...(options.tracing ? ['@sentry/tracing'] : []), ] for (const dep of aliasedDependencies) { - nuxt.options.alias[`~${dep}`] = (await resolvePath(dep)).replace(/\/cjs\//, '/esm/') + nuxt.options.alias[`~${dep}`] = (await resolvePath(dep, { url: moduleDir })).replace(/\/cjs\//, '/esm/') } - nuxt.options.alias['~@sentry/browser-sdk'] = (await resolvePath('@sentry/browser/esm/sdk')) + nuxt.options.alias['~@sentry/browser-sdk'] = (await resolvePath('@sentry/browser/esm/sdk', { url: moduleDir })) if (serverSentryEnabled(options)) { /**