Repository navigation
@sentry/nextjs 7.15 and 7.16 have issues with @vercel/nft #5998
Description
Activity
Hi, thanks for reporting this and providing a ton of information. I am able to reproduce this.
The
autoInstrumentServerFunctionsis 100% responsible for this. In the meanwhile, to get your stuff working again, you can setautoInstrumentServerFunctions: falseinnext.config.js(docs).We did something somewhat risky with this feature and issues like these just simply didn't come up during development - sorry for the inconvenience! If you figure out any workarounds or have solutions in mind, let us know!
We'll try to find a fix.
Reacted by Alexander KachkaevThanks @lforst! Setting
autoInstrumentServerFunctionstofalseworked: blockprotocol/blockprotocol#694.Happy to try out new ideas Sentry team comes up with 👍
Reacted by Luca ForstnerMy team is also experiencing this same issue. Trying the
autoInstrumentServerFunctions: falsefix now. For us it was giving us this error:ERROR Error: ENOENT: no such file or directory, openlinking to our email template files.Edit: as per @kachkaev
autoInstrumentServerFunctions: falsefix is working and we are no longer receiving the error.Reacted by Jasmin@kachkaev - Echoing @lforst here: Thanks for such a thorough writeup and investigation!
It's not entirely clear yet, but fixing this may mean trying to contribute an upstream patch to the nft package. I'm going to dive into it for a bit and see what I can figure out, then ping vercel folks in a few days once they're no longer actively in the middle of their nextjs conference.
UPDATE 1: Checked out the nft files you linked and ugh - the problem is actually worse than I realized. Yes,
data.jsonis gone, which is a problem. But the map files added in the 7.13/7.14 versions ought not to be there (they're big and not helpful at runtime given that everything is running on an inaccessible AWS server somewhere), and a great number of the files added in the 7.15/7.16 versions also ought not to be there, since they're only needed at build time, not runtime. At the same time, I'm wondering why there are no sentry files at all in the 7.13/7.14 versions... 😓UPDATE 2: Okay, question 1 solved. The 7.13/7.14 versions have no sentry files because the API route isn't using
withSentry. Sentry stuff does show up in the_appnft file when I clone your repo and build locally.Oy. Okay. Time to clone the nft repo! 🙂
Reacted by Alexander KachkaevI think we're running into a similar issue here, except with a different package.
The only api routes we have in our next.js application are with https://github.com/auth0/nextjs-auth0, and disablingautoInstrumentServerFunctionshas things working again.@alechartung - Sorry, I'm not sure what you mean. This issue is specifically about the nft files missing dependencies from the page files we wrap. How does
nextjs-auth0play into it?Maybe it's not the same exact issue and just has the same workaround, then.
Yes, it turns out there are any number of ways for the autowrapping to not play nicely with other packages. Would you please file a separate issue and give the details of the error you’re running into?
Reacted by Alec HartungAppreciate the thorough write-up, @kachkaev 👍 We're running into the same issue. Trying to
readFilefrom our API routes to generate emails from template files on the server.Have forked the MWE repo, upgraded
@sentry/nextjsto the latest7.21.1, but the issue still persists.Our current workaround is to use its new
excludeServerRoutesconfig option to ignore this particular API route that needs filesystem access. E.g.const moduleExports = { sentry: { excludeServerRoutes: ['/api/hello'] } }
Reacted by Alexander KachkaevI have a PR open in the nft repo to fix the underlying cause of this problem. Until that's merged, if you use
patch-package, here's a patch I made for my test app which applies the changes from the PR. (UPDATE: I realized that to make this work you also need dependencies from@vercel/nft, which I already happened to have. Probably easier to just wait for the fix to merge...)
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
@sentry/nextjs
SDK Version
7.15.0 / 7.16.0
Framework Version
Next 12.3.1
Link to Sentry event
No response
Steps to Reproduce
When upgrading blockprotocol/blockprotocol from
@sentry/nextjs@7.13.0to7.15.0or7.16.0, my app started responding with 500 on Vercel. It was working fine locally, which did not make sense at first. I managed to link this problem to@vercel/nft(part of Next.js) and created an MWE here:https://github.com/hasharchives/sentry-vercel-nft-issue/branches/all
The bug it is to do with Sentry corrupting
*.nft.jsonbuild files.The default
no-sentrybranch in my MWE contains a simple Next.js app that consists of a page withgetServerSidePropsand an API route. Both files readdata.jsonin the repo root. When the app is built, Next creates.next/server/pages/**/*.nft.jsonfiles which are then used on Vercel to determine which files to include in which lambdas. These files are normally.gitignore-ed but I’ve added them to the MWE repo:no-sentry.next/server/pages/index.js.nft.jsonno-sentry.next/server/pages/api/hello.js.nft.jsonAutogenerated
*.nft.jsonfiles are one-liners. I ranyarn dlx prettier --write .next/server/pages/**/*.nft.jsonand then ordered file paths alphabetically to ease comparison.As you can see, both files above refer
data.jsonwhich is correct.Installing
@sentry/nextjs@7.13.0or@sentry/nextjs@7.14.0results in more items in*.nft.jsonbut does not affect the presence ofdata.json– that’s good:sentry-7.13.next/server/pages/index.js.nft.jsonsentry-7.13.next/server/pages/api/hello.js.nft.jsonsentry-7.14.next/server/pages/index.js.nft.jsonsentry-7.14.next/server/pages/api/hello.js.nft.jsonHowever, switching to newer versions of
@sentry/nextjscausesdata.jsonto disappear:sentry-7.15.next/server/pages/index.js.nft.jsonsentry-7.15.next/server/pages/api/hello.js.nft.jsonsentry-7.16.next/server/pages/index.js.nft.jsonsentry-7.16.next/server/pages/api/hello.js.nft.jsonAlthough the result of
next buildworks locally viayarn start, the Vercel deployment ends up corrupt because of the missing references. Lambda logs show this:Expected Result
data.jsonis included in*.nft.jsonfiles for all tested@sentry/nextjsversions.Actual Result
data.jsonis included in*.nft.jsonfiles for@sentry/nextjs@7.13.0and@sentry/nextjs@7.14.2, but not for@sentry/nextjs@7.15.0and@sentry/nextjs@7.16.0. When the app is deployed to Vercel withoutdata.jsonin*.nft.json, lambdas crash because the cannot open the file.Links
autoInstrumentServerFunctionsper default #5919