You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Next 13 + App Router + static export results in a build error (Specified "rewrites" cannot be used with "output: export") #8285
I've used the wizard to create the sentry.*.config.js files. My next.config.js is: { images: { unoptimized: true }, experimental: { externalDir: true }, output: 'export', reactStrictMode: true }
Steps to Reproduce
I'm using the Next with the App Router in a static configuration (output: 'export' in next.config.js).
When attempting to build the app, I'm getting:
> Build error occurred Error: Specified "rewrites" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes at assignDefaults (/Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/config.js:218:19) at loadConfig (/Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/config.js:550:32) at async Span.traceAsyncFn (/Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/trace/trace.js:103:20) at async /Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/index.js:150:28 at async Span.traceAsyncFn (/Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/trace/trace.js:103:20) at async build (/Users/eran/Dev/Butterfly/Website/node_modules/.pnpm/next@13.4.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/index.js:145:29)
This error started following the integration of the Sentry SDK. This error is suppressed when I remove the output: 'export' option.
Hey Can you please try the below changes and updates
Option 1:
Use "target: serverless" instead of "output: export"
Instead of using "output: export", you can try setting the "target" configuration to "serverless" in your Next.js configuration file (usually next.config.js). This target is compatible with the Sentry SDK and may resolve the build error. Here's an example of how you can set the "target" configuration:
javascript
Copy code
Update Sentry SDK version
It's possible that the issue is related to the version of the Sentry SDK you're using. Try updating to the latest version of the Sentry SDK to see if it resolves the conflict with "output: export". You can update the package by running the following command in your project directory:
Hi @metalmarker, please ignore @alikazi88's responses. It looks like they copied & pasted this issue into something like chat GPT and their answer is straight-up wrong and not helpful.
Can you please share your next.config.js? You probably have the tunnelRoute option set which is an option that uses the server runtime and the server runtime is obviously not available when doing a static export.
@lforst - thanks for the quick reply. The tunnelRoute was indeed set (it was added by the Next configuration wizard) and upon removal I was able to build the static code without that error.
After generating the static export, I served it from my local machine. Now, however, I see no source code at all when triggering an error. I verified that the source maps for the last build were added under the project (under "Release bundles", not Artifact bundles).
Hey, I recommend turning off the silent flag and taking a look at the logs when building. Maybe there's something there that will tell us what's wrong.
I've turned silent off and there are no errors or warnings. According to the logs the source maps are successfully uploaded to your server for processing (and they do appear right afterwards under the project / source maps / release bundles).
Here are two errors, one in local "production" and one in development mode, triggered by the same code:
This error was generated by a static export that I’m serving from my local machine. Source code is not displayed.
This error was generated when I run Next in development mode. Source code is displayed, but there’s an error: “We've encountered 1 problem un-minifying your applications source code / Invalid absolute path URL.
@metalmarker since you're doing an export and likely serving stuff from a different path than when just doing next start you need to play around with the webpack plugin options to make the stack trace filenames line up with the uploaded artifacts.
@lforst, I've invested several hours in trying to crack this, but was unsuccessful so far.
Can you point me to the options that might be off for the export scenario? Also, I'm not sure why the source maps appear under the deprecated "release bundles" instead of the "artifact bundles". Perhaps that's related. Thanks!
Hi @metalmarker, please ignore @alikazi88's responses. It looks like they copied & pasted this issue into something like chat GPT and their answer is straight-up wrong and not helpful.
Can you please share your next.config.js? You probably have the tunnelRoute option set which is an option that uses the server runtime and the server runtime is obviously not available when doing a static export.
this solved the problem for me as well. The tunnelRoute option is set by the Sentry wizard
Activity
alikazi88 commentedon Jun 3, 2023
Hey Can you please try the below changes and updates
Option 1:
Use "target: serverless" instead of "output: export"
Instead of using "output: export", you can try setting the "target" configuration to "serverless" in your Next.js configuration file (usually next.config.js). This target is compatible with the Sentry SDK and may resolve the build error. Here's an example of how you can set the "target" configuration:
javascript
Copy code
or
Option 2:
Update Sentry SDK version
It's possible that the issue is related to the version of the Sentry SDK you're using. Try updating to the latest version of the Sentry SDK to see if it resolves the conflict with "output: export". You can update the package by running the following command in your project directory:
metalmarker commentedon Jun 3, 2023
No go:
lforst commentedon Jun 5, 2023
Hi @metalmarker, please ignore @alikazi88's responses. It looks like they copied & pasted this issue into something like chat GPT and their answer is straight-up wrong and not helpful.
Can you please share your
next.config.js? You probably have thetunnelRouteoption set which is an option that uses the server runtime and the server runtime is obviously not available when doing a static export.metalmarker commentedon Jun 5, 2023
@lforst - thanks for the quick reply. The tunnelRoute was indeed set (it was added by the Next configuration wizard) and upon removal I was able to build the static code without that error.
After generating the static export, I served it from my local machine. Now, however, I see no source code at all when triggering an error. I verified that the source maps for the last build were added under the project (under "Release bundles", not Artifact bundles).
Here is my
next.config.js:lforst commentedon Jun 5, 2023
Hey, I recommend turning off the
silentflag and taking a look at the logs when building. Maybe there's something there that will tell us what's wrong.metalmarker commentedon Jun 5, 2023
I've turned
silentoff and there are no errors or warnings. According to the logs the source maps are successfully uploaded to your server for processing (and they do appear right afterwards under the project / source maps / release bundles).lforst commentedon Jun 5, 2023
Can you share a link to the event that doesn't have a stacktrace? Thanks.
metalmarker commentedon Jun 5, 2023
Here are two errors, one in local "production" and one in development mode, triggered by the same code:
This error was generated by a static export that I’m serving from my local machine. Source code is not displayed.
This error was generated when I run Next in development mode. Source code is displayed, but there’s an error: “We've encountered 1 problem un-minifying your applications source code / Invalid absolute path URL.
lforst commentedon Jun 6, 2023
@metalmarker since you're doing an export and likely serving stuff from a different path than when just doing
next startyou need to play around with the webpack plugin options to make the stack trace filenames line up with the uploaded artifacts.https://www.npmjs.com/package/@sentry/webpack-plugin/v/1.20.1
metalmarker commentedon Jun 6, 2023
@lforst, I've invested several hours in trying to crack this, but was unsuccessful so far.
Can you point me to the options that might be off for the export scenario? Also, I'm not sure why the source maps appear under the deprecated "release bundles" instead of the "artifact bundles". Perhaps that's related. Thanks!
metalmarker commentedon Jun 14, 2023
@lforst, bumping this up... surely this is something that others would encounter on similar configuration
aaarichter commentedon Jul 4, 2023
this solved the problem for me as well. The
tunnelRouteoption is set by the Sentry wizard