sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Sentry creates rewriteFramesHelper.js during Nextjs "standalone" static generation

Open calix opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Self-hosted/on-premise

Which package are you using?

@sentry/nextjs

SDK Version

6.18.1

Framework Version

No response

Link to Sentry event

No response

Steps to Reproduce

We are switching to generating a standalone bundle for our Nextjs project according to: https://nextjs.org/docs/advanced-features/output-file-tracing

This issue is possible to reproduce when bundling NextJS using:

module.exports = { experimental: { outputStandalone: true, }, }

next.config.js consumes the config using withSentryConfig as described in the docs:

module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions);

We first detected the issue when our Azure pipeline failed at:

> Build error occurred [Error: ENOENT: no such file or directory, mkdir 'D:\a\1\s\.next\standalone\.next\server\pages\C:\Users\VSSADM~1\AppData\Local\Temp\sentry-Yr02pe'] { errno: -4058, code: 'ENOENT', syscall: 'mkdir', path: 'D:\\a\\1\\s\\.next\\standalone\\.next\\server\\pages\\C:\\Users\\VSSADM~1\\AppData\\Local\\Temp\\sentry-Yr02pe' } ##[error]Cmd.exe exited with code '1'. Sentry is for some reason trying to generate a folder for the file rewritesFramesHelper.js during nextjs "Generating static pages".

When running locally, this directory is created in the root NextJS folder.

Expected Result

Expect sentry not to spam the project folder with directory sentry-xxxxx.

Actual Result

image

As you can see, Sentry is creating a folder Users...../sentry-xxxxxx containing rewritesFramesHelper.js.

calix avatar Mar 04 '22 12:03 calix

This is the logic that concerns itself with this - https://github.com/getsentry/sentry-javascript/blob/889024a8b9da0664447f157eacaaf8713d6cc7d4/packages/nextjs/src/config/webpack.ts#L135-L148, but it seems that it doesn't account for .next/standalone.

Adding to the backlog, but PRs are welcome for anyone who wants to help out!

AbhiPrasad avatar Mar 07 '22 13:03 AbhiPrasad

This is related to https://github.com/getsentry/sentry-javascript/issues/4382, or rather, solving one will solve both.

Two possible approaches:

  1. Do what the webpack plugin does and rather than create a new file, have a placeholder file whose contents we replace. Potential problem: Can we guarantee we know where that file will be within node_modules?

  2. Instead of adding a new file to the webpack entry property, create a loader which inserts the code directly into the necessary files.

lobsterkatie avatar Mar 14 '22 04:03 lobsterkatie

I can mention that we have temporarily solved this by patching (using patch-package) the node module for this library. Its not a pretty patch but seems to work.

calix avatar Mar 14 '22 07:03 calix

Hello, we also have this problem, when building the nextjs app with outputStandalone: true on our Jenkins, we get the following error message:

> Build error occurred
[Error: EACCES: permission denied, mkdir '/var/lib/tmp'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/var/lib/tmp'
}

Of course this path is protected on our Jenkins.

When debugging locally, I found out that Sentry writes a JS file to the tmp dir:

cat /var/lib/tmp/sentry-BLeAPp/rewriteFramesHelper.js 
global.__rewriteFramesDistDir__ = '.next';

bogdankatishev avatar Mar 16 '22 13:03 bogdankatishev

When debugging locally, I found out that Sentry writes a JS file to the tmp dir

Yup, that is indeed what we do. Interesting that it's protected... I would have said the whole point of a temp folder was for processes to be able to throw whatever temporary files they need to in there without having to worry about cleaning them up, and protecting it completely defeats that purpose.

Regardless, in the long run, I think it's reasonable to change our approach, using one of the two strategies I outlined above. In the short run, would any of the strategies listed here solve your problem?

lobsterkatie avatar Mar 17 '22 01:03 lobsterkatie

I met the same problem. rewriteFramesHelper.js is created in other folder. Is there any way we can fix this quickly?

webPlayer7 avatar Apr 12 '22 04:04 webPlayer7

I can mention that we have temporarily solved this by patching (using patch-package) the node module for this library. Its not a pretty patch but seems to work.

Hey @calix can you share your patch, however ugly?

svict4 avatar May 13 '22 03:05 svict4

That error disappear when I build in Linux. It occurs when only windows OS

webPlayer7 avatar May 13 '22 04:05 webPlayer7

I meet the same problem, during build sentry want create new folder but with weird path D:\\MyProjects\\next-app\\.next\\standalone\\.next\\server\\pages\\C:\\Users\\USER\\AppData\\Local\\Temp\\sentry-zVQYAF You see it try connect 2 paths. Error occurs on windows.

GorlikItsMe avatar Jun 21 '22 13:06 GorlikItsMe

Setting the TMP environment variable to a directory inside of my project tree fixed the mkdir issue for me.

lesderid avatar Oct 25 '22 10:10 lesderid

Sorry - This should have been marked as fixed in https://github.com/getsentry/sentry-javascript/pull/5445, which was first included in version 7.8.0. I'm going to close this, but please let me know if it's still happening for you in a later version.

lobsterkatie avatar Oct 27 '22 02:10 lobsterkatie