Skip to content

fix(nextjs): Inject init code via relative path #8135

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

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 5 additions & 2 deletions packages/nextjs/src/config/loaders/wrappingLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Collaborator

@timfish timfish May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the check here for isAbsolute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think webpack really defines what the value behind this looks like. Usually it is an absolute path but I think it could also be some virtual module and stuff and we can't create relative imports for virtual modules so it is just a check for the cases we can actually handle. Does this make sense?

// 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;
Expand Down