Skip to content

Commit

Permalink
fix(nextjs): Guard for non-absolute paths when injecting sentry config (
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed May 22, 2023
1 parent ea551c9 commit 3dd4a58
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/nextjs/src/config/loaders/wrappingLoader.ts
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

0 comments on commit 3dd4a58

Please sign in to comment.