diff --git a/packages/nextjs/src/config/loaders/wrappingLoader.ts b/packages/nextjs/src/config/loaders/wrappingLoader.ts index 28c8f58b2eb9..3f69b79faaa2 100644 --- a/packages/nextjs/src/config/loaders/wrappingLoader.ts +++ b/packages/nextjs/src/config/loaders/wrappingLoader.ts @@ -202,8 +202,11 @@ export default function wrappingLoader( templateCode = templateCode.replace(/__COMPONENT_TYPE__/g, 'Unknown'); } - if (sentryConfigFilePath) { - templateCode = `import "${sentryConfigFilePath}";`.concat(templateCode); + // We check that `this.resourcePath` is absolte because webpack doesn't really have a contract for what the value looks like. It could basically be anything. + if (sentryConfigFilePath && path.isAbsolute(this.resourcePath)) { + // Get path relative to current module because webpack can't handle absolute paths on windows: https://github.com/getsentry/sentry-javascript/issues/8133 + const sentryConfigFileImportPath = path.relative(path.dirname(this.resourcePath), sentryConfigFilePath); + templateCode = `import "${sentryConfigFileImportPath}";`.concat(templateCode); } } else if (wrappingTargetKind === 'middleware') { templateCode = middlewareWrapperTemplateCode;