Skip to content

Commit

Permalink
fix(nextjs): Ensure imports are valid relative paths (#8799)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Aug 11, 2023
1 parent 797d906 commit e259aa7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/nextjs/src/config/loaders/wrappingLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ export default function wrappingLoader(
const sentryConfigImportPath = path
.relative(path.dirname(this.resourcePath), sentryConfigFilePath)
.replace(/\\/g, '/');
templateCode = templateCode.replace(/__SENTRY_CONFIG_IMPORT_PATH__/g, sentryConfigImportPath);

// path.relative() may return something like `sentry.server.config.js` which is not allowed. Imports from the
// current directory need to start with './'.This is why we prepend the path with './', which should always again
// be a valid relative path.
// https://github.com/getsentry/sentry-javascript/issues/8798
templateCode = templateCode.replace(/__SENTRY_CONFIG_IMPORT_PATH__/g, `./${sentryConfigImportPath}`);
} else {
// Bail without doing any wrapping
this.callback(null, userCode, userModuleSourceMap);
Expand Down

0 comments on commit e259aa7

Please sign in to comment.