Skip to content

ERR_INVALID_URL for next config rewrite option #6381

Description

@Naddiseo

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.23.0

Framework Version

13.0.6-canary.3

Link to Sentry event

No response

Steps to Reproduce

  1. a next config
// next.config.jsimport{withSentryConfig}from"@sentry/nextjs";constrewrites=async()=>{constapiUrl=process.env.API_URL.trim();if(!(process.env.SENTRY_DSN||process.env.NEXT_PUBLIC_SENTRY_DSN)){thrownewError("process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN must be defined");}constsentryUrl=newURL(process.env.SENTRY_DSN||process.env.NEXT_PUBLIC_SENTRY_DSN);constsentryProjectId=sentryUrl.pathname.replace("/","");sentryUrl.pathname=`/api/${sentryProjectId}/envelope/`;constsentryProxyURL=sentryUrl.toString();return[{source: "/:path*",destination: "/:path*",},{source: "/sentry",destination: sentryProxyURL,basePath: false,},];};constmoduleExports={
rewrites,reactStrictMode: true,};constSentryWebpackPluginOptions={silent: true,};exportdefaultwithSentryConfig(moduleExports,SentryWebpackPluginOptions);
  1. run next build

Expected Result

It should build correctly.

Actual Result

next build
info - Loaded env from .env.local
info - Skipping validation of types
info - Linting info - Creating an optimized production build info - Compiled successfully
info - Collecting page data ..TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:387:5)
at URL.onParseError (node:internal/url:565:9)
at new URL (node:internal/url:641:5)
at Object.makeNodeTransport [as transport] (/node_modules/@sentry/node/cjs/transports/http.js:34:23)
at new BaseClient (/node_modules/@sentry/core/cjs/baseclient.js:70:33)
at new NodeClient (/node_modules/@sentry/node/cjs/client.js:44:5)
at Object.initAndBind (/node_modules/@sentry/core/cjs/sdk.js:34:18)
at Object.init (/node_modules/@sentry/node/cjs/sdk.js:159:8)
at Object.init (/node_modules/@sentry/nextjs/cjs/index.server.js:69:8)
at Object.9673 (/.next/server/chunks/290.js:19:45) {
input: '/sentry',
code: 'ERR_INVALID_URL'
}
> Build error occurred
Error: Failed to collect page data for /homepage
at /node_modules/next/dist/build/utils.js:959:15
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
type: 'Error'
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions