Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions packages/nextjs/src/config/loaders/wrappingLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,13 @@ export default function wrappingLoader(
templateCode = templateCode.replace(/__COMPONENT_TYPE__/g, 'Unknown');
}

if (sentryConfigFilePath) {
let importPath = sentryConfigFilePath;

// absolute paths do not work with Windows
// https://github.com/getsentry/sentry-javascript/issues/8133
if (path.isAbsolute(importPath)) {
importPath = path.relative(path.dirname(this.resourcePath), importPath);
}

templateCode = `import "${importPath.replace(/\\/g, '/')}";\n`.concat(templateCode);
// We check whether `this.resourcePath` is absolute because there is no contract by webpack that says it is absolute,
// however we can only create relative paths to the sentry config from absolute paths.Examples where this could possibly be non - absolute are virtual modules.
if (sentryConfigFilePath && path.isAbsolute(this.resourcePath)) {
const sentryConfigImportPath = path
.relative(path.dirname(this.resourcePath), sentryConfigFilePath) // Absolute paths do not work with Windows: https://github.com/getsentry/sentry-javascript/issues/8133
.replace(/\\/g, '/');
templateCode = `import "${sentryConfigImportPath}";\n`.concat(templateCode);
}
} else if (wrappingTargetKind === 'middleware') {
templateCode = middlewareWrapperTemplateCode;
Expand Down