Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Guard for non-absolute paths when injecting sentry config #8151

Merged
merged 2 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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