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): Inject init code via relative path #8135

Closed
wants to merge 5 commits into from

Conversation

lforst
Copy link
Member

@lforst lforst commented May 16, 2023

Potentially fixes #8133

@@ -79,6 +79,8 @@ export default function wrappingLoader(
vercelCronsConfig,
} = 'getOptions' in this ? this.getOptions() : this.query;

this.resourcePath;
Copy link
Member

Choose a reason for hiding this comment

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

can we remove this?

@github-actions
Copy link
Contributor

github-actions bot commented May 16, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.03 KB (+0.03% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.63 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.57 KB (+0.04% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.09 KB (+0.02% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.17 KB (0%)
@sentry/browser - Webpack (minified) 69.04 KB (0%)
@sentry/react - Webpack (gzipped + minified) 21.19 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.12 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.65 KB (+0.03% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.89 KB (+0.04% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 48.19 KB (+1.21% 🔺)
@sentry/replay - Webpack (gzipped + minified) 42.06 KB (+1.45% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 67.15 KB (+0.97% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60.05 KB (+1.13% 🔺)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Let's merge after @timfish confirms

Copy link
Collaborator

@timfish timfish left a comment

Choose a reason for hiding this comment

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

See my alternative PR here:
#8142

templateCode = `import "${sentryConfigFilePath}";`.concat(templateCode);
if (sentryConfigFilePath && path.isAbsolute(this.resourcePath)) {
const sentryConfigFileImportPath = path
.relative(this.resourcePath, sentryConfigFilePath) // Get path relative to current module because webpack can't handle absolute paths on windows: https://github.com/getsentry/sentry-javascript/issues/8133
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be path.dirname(this.resourcePath) otherwise the relative path goes up one level too far

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea that seems to be the most important thing!

@@ -202,8 +202,13 @@ export default function wrappingLoader(
templateCode = templateCode.replace(/__COMPONENT_TYPE__/g, 'Unknown');
}

if (sentryConfigFilePath) {
templateCode = `import "${sentryConfigFilePath}";`.concat(templateCode);
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
Member 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?

if (sentryConfigFilePath && path.isAbsolute(this.resourcePath)) {
const sentryConfigFileImportPath = path
.relative(this.resourcePath, sentryConfigFilePath) // Get path relative to current module because webpack can't handle absolute paths on windows: https://github.com/getsentry/sentry-javascript/issues/8133
.replace(/\.[^/.]+$/, ''); // Remove the file extension from the import
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.

You also need to replace every \ with /. Import paths cannot use backslashes?

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.

It's worth noting that in my testing, the file extension didn't seem to matter!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah thanks for pointing that out. Was just messing around here and yeah doesn't seem to fix anything haha

@lforst lforst closed this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Next 13 Module build failed UnhandledSchemeError
3 participants