Skip to content

ref(nextjs): Use resolved paths for require calls in config code #3426

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

Merged
merged 4 commits into from
Apr 23, 2021

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Apr 20, 2021

Currently, we use relative paths for the require calls in syncPluginVersionWithNextVersion. Though this works most of the time, it depends on the particular structure of the user's node_modules directory, which is mostly predictable but not guaranteed. This PR therefore switches to using a combination of require.resolve and a recursive search up the file hierarchy to find the package.json files we need.

Fixes #3424.
Fixes #3430.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 20, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.61 KB (0%)
@sentry/browser - Webpack 21.49 KB (0%)
@sentry/react - Webpack 21.53 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 27.91 KB (+0.01% 🔺)

@dcramer
Copy link
Member

dcramer commented Apr 20, 2021

Will this not still expect everything to live at the project's node_modules path? vs node_modules/@sentry/nextjs/node_modules?

ideally it would just replicate npm's resolver code to find the other module

@lobsterkatie
Copy link
Member Author

lobsterkatie commented Apr 20, 2021

@dcramer - fair point. As it turns out to be more complicated than one might like, I'm going to outsource the task.

@dcramer
Copy link
Member

dcramer commented Apr 20, 2021

this is super off topic, but something we might want to consider.. given complexity of vulnerabiltiies/deps in sdks.

what if we vendored third party deps? im assuming (and praying) we have very few, and it'd make everyone more comfortable knowing the dep graph isnt 1000+ random npm modules that might change under the hood and cause customers more security vetting

@lobsterkatie
Copy link
Member Author

@dcramer It's funny you should say that... The library I linked above turns out to be non-ESM compliant (export = ...), which breaks our build, and so as a stopgap I just copied the transpiled JS over to our nextjs package and figured we'd just vendor it until it got fixed. (I haven't pushed it yet because I'm fighting with TS at the moment.) Doing that as a permanent solution is another story, and I see real pros and cons there. Definitely something to think about, though.

@lobsterkatie lobsterkatie marked this pull request as draft April 20, 2021 22:15
@Tevinthuku
Copy link

Tevinthuku commented Apr 21, 2021

@lobsterkatie ,Will using resolve-package-path as you mentioned help in getting the package location in a yarn-workspace setup where the packages are hoisted?
....

I think it's best if I create an issue with the exact problem that Im facing . Done #3430

@lobsterkatie lobsterkatie force-pushed the kmclb-use-abs-paths-for-nextjs-config branch 2 times, most recently from 87b00ed to 8465659 Compare April 22, 2021 03:09
@lobsterkatie lobsterkatie marked this pull request as ready for review April 22, 2021 03:10
@lobsterkatie lobsterkatie force-pushed the kmclb-use-abs-paths-for-nextjs-config branch from 8465659 to 79ca864 Compare April 22, 2021 03:11
@lobsterkatie
Copy link
Member Author

lobsterkatie commented Apr 22, 2021

@Tevinthuku Yes, I believe it should, though I didn't end up using that library, as it's broken for ESM builds (see my note above), and vendoring it turned out to be more trouble than it was worth.

Once this is merged and released, which should be in the next few days, please let me know if you're still having trouble.

@HazAT
Copy link
Member

HazAT commented Apr 22, 2021

Can we also fix this: #3441 ?

@iker-barriocanal
Copy link
Contributor

Can we also fix this: #3441 ?

Addressing it here: #3444

@lobsterkatie
Copy link
Member Author

Can we also fix this: #3441 ?

Addressing it here: #3444

I think #3444 fixes only part of #3441 - it will stop sentry problems from turning into breaking-the-world problems, but it doesn't address the read-only nature of the vercel filesystem. In other words, we won't crash people's apps, but the plugin won't work, either. Still I think it's a good thing to do, and we can address the read-only part in a separate PR.

@iker-barriocanal iker-barriocanal merged commit 7fb0c2a into master Apr 23, 2021
@iker-barriocanal iker-barriocanal deleted the kmclb-use-abs-paths-for-nextjs-config branch April 23, 2021 10:29
@Tevinthuku
Copy link

I got to test the new release of the plugin & Im getting this error,

image

This line is the culprit,

import '../../../../sentry.client.config.js';

I tried commenting it out locally to see what happens & the same error occurs, but now on the on-init-server.js file.

@lobsterkatie
Copy link
Member Author

@Tevinthuku -Thanks. Can you please file an issue with pretty much exactly what you have in your comment? I'll work on a fix in the meantime.

@Tevinthuku
Copy link

Tevinthuku commented Apr 24, 2021

Sure thing.
Done #3452

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.

nextjs yarn-workspace issue (no such file/directory) @sentry/nextjs dependency fails to load next-plugin-sentry
6 participants