Repository navigation
Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
- a next config
// next.config.js
import { withSentryConfig } from "@sentry/nextjs";
const rewrites = async () => {
const apiUrl = process.env.API_URL.trim();
if (!(process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN)) {
throw new Error("process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN must be defined");
}
const sentryUrl = new URL(process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN);
const sentryProjectId = sentryUrl.pathname.replace("/", "");
sentryUrl.pathname = `/api/${sentryProjectId}/envelope/`;
const sentryProxyURL = sentryUrl.toString();
return [
{
source: "/:path*",
destination: "/:path*",
},
{
source: "/sentry",
destination: sentryProxyURL,
basePath: false,
},
];
};
const moduleExports = {
rewrites,
reactStrictMode: true,
};
const SentryWebpackPluginOptions = {
silent: true,
};
export default withSentryConfig(moduleExports, SentryWebpackPluginOptions);- 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'
}
Metadata
Metadata
Assignees
Labels
No labels
Activity
lforst commentedon Dec 2, 2022
Hi, you're not mapping the DSN to a URL correctly. You still have the part with
xxx@in there.You need to map it from
https://publicKey@o111111.ingest.sentry.io/22222tohttps://o111111.ingest.sentry.io/api/22222/envelope/?sentry_key=publicKey. You currently havehttps://publicKey@o111111.ingest.sentry.io/api/22222/envelope/.lforst commentedon Dec 2, 2022
Also, have you set a proper dsn in your init calls?
Naddiseo commentedon Dec 2, 2022
Sorry, my report yesterday wasn't well structured, I hadn't slept well.
The back story of this report, is that it was working early last year, then a combination of moving to production (on Vercel) and upgrading next broke my code. I had a long standing bug report on next that I've now been asked to reproduce the issue with canary. I have since worked around the original issue using tunneling
Yes:
That doesn't appear the be the issue, if I make the following change, it still has the
ERR_INVALID_URL.The issue is that @sentry/next seems to calling
new URL(rewrite.source)somewhere. If I open up a node console I get the same thing:I have just noticed that in my comment on the tunnelling example I did mention solving the
ERR_INVALID_URLissue by not having atunnel:"/sentry"in sentry.server.config.ts. So I guess, this bug report is more to do with rewrite + tunnel on the server side build?Regardless of what is causing it, it's not easy to track down what the cause of the error is, and it might be something
@sentry/nextjschecks for?lforst commentedon Dec 5, 2022
in which init call are you setting
tunnel? Insentry.client.config.jsor insentry.server.config.js?Naddiseo commentedon Dec 5, 2022
Having
"tunnel": "/sentry"insentry.server.config.jsis what causes theERR_INVALID_URLissue.lforst commentedon Dec 5, 2022
Right. Unless you actually want to tunnel server events that originate from the server (can't think of a use case here), you should set the
tunneloption only insentry.client.config.js. If you really want to tunnel server events you must provide an absolute URL if I am not mistaken.Naddiseo commentedon Dec 5, 2022
Yes, of course. However, the error message doesn't tell me this, and it took quite a bit of debugging to come to that conclusion; it would have saved me some debugging cycles if sentry had verified my config was correct.
lforst commentedon Dec 6, 2022
We should probably clarify the docs that the common use case for
tunnelis only in the client. If you want to improve the error message, PRs welcome!Could you resolve your issue?
github-actions commentedon Dec 28, 2022
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it
Status: BacklogorStatus: In Progress, I will leave it alone ... forever!"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
fix(nextjs): Check for invalid tunnel option on server
Naddiseo commentedon Dec 28, 2022
I added a PR to throw a better error message
lforst commentedon Dec 30, 2022
@Naddiseo thanks for opening a PR. Just out of curiosity, how are you using tunneling serverside? Normally it is just something you would do on the browser because of ad blockers.
Naddiseo commentedon Dec 30, 2022
Adding tunneling server side was by accident because I didn't read the docs close enough and I had copy/pasted the client config into the server one. Then I got very confused by this error message.