Skip to content

Commit e259aa7

Browse files
author
Luca Forstner
authored
fix(nextjs): Ensure imports are valid relative paths (#8799)
1 parent 797d906 commit e259aa7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/nextjs/src/config/loaders/wrappingLoader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ export default function wrappingLoader(
9696
const sentryConfigImportPath = path
9797
.relative(path.dirname(this.resourcePath), sentryConfigFilePath)
9898
.replace(/\\/g, '/');
99-
templateCode = templateCode.replace(/__SENTRY_CONFIG_IMPORT_PATH__/g, sentryConfigImportPath);
99+
100+
// path.relative() may return something like `sentry.server.config.js` which is not allowed. Imports from the
101+
// current directory need to start with './'.This is why we prepend the path with './', which should always again
102+
// be a valid relative path.
103+
// https://github.com/getsentry/sentry-javascript/issues/8798
104+
templateCode = templateCode.replace(/__SENTRY_CONFIG_IMPORT_PATH__/g, `./${sentryConfigImportPath}`);
100105
} else {
101106
// Bail without doing any wrapping
102107
this.callback(null, userCode, userModuleSourceMap);

0 commit comments

Comments
 (0)