New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nextjs 13 / Cypress: TypeError: Cannot convert undefined or null to object #6059
Comments
Hi, thanks for writing in! Since Next.js 13 is quite new and the sources of errors are currently quite unclear, can I ask you to do two things to make debugging this easier?
Thank you! |
Hi @lforst !! I've the same issue when building my app inside a Docker image, let's see if this helps you to detect the issue. I've tried the following (which didn't work for me):
sentry: {
autoInstrumentServerFunctions: false,
}, ☝️ This didn't work for me, and I decided to:
const SENTRY_ENABLED = false;
if (SENTRY_ENABLED && process.env.NODE_ENV !== 'development') {
config = withSentryConfig(config, {
silent: true,
url: process.env.SENTRY_URL,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
});
} After adding this piece of code and build the docker image again, the error still persists. So I decided to manually add a NextServer {
options: {
dir: '/home/node',
hostname: 'localhost',
port: 8080,
keepAliveTimeout: undefined,
customServer: false,
httpServer: Server {
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
requestTimeout: 300000,
headersTimeout: 60000,
keepAliveTimeout: 5000,
connectionsCheckingInterval: 30000,
_events: [Object: null prototype],
_eventsCount: 5,
_maxListeners: undefined,
_connections: 2,
_handle: [TCP],
_usingWorkers: false,
_workers: [],
_unref: false,
allowHalfOpen: true,
pauseOnConnect: false,
noDelay: true,
keepAlive: false,
keepAliveInitialDelay: 0,
httpAllowHalfOpen: false,
timeout: 0,
maxHeadersCount: null,
maxRequestsPerSocket: 0,
_connectionKey: '4:0.0.0.0:8080',
[Symbol(IncomingMessage)]: [Function: IncomingMessage],
[Symbol(ServerResponse)]: [Function: ServerResponse],
[Symbol(kCapture)]: false,
[Symbol(async_id_symbol)]: 10,
[Symbol(http.server.connections)]: ConnectionsList {},
[Symbol(http.server.connectionsCheckingInterval)]: Timeout {
_idleTimeout: 30000,
_idlePrev: [TimersList],
_idleNext: [TimersList],
_idleStart: 945,
_onTimeout: [Function: bound checkConnections],
_timerArgs: undefined,
_repeat: 30000,
_destroyed: false,
[Symbol(refed)]: false,
[Symbol(kHasPrimitive)]: false,
[Symbol(asyncId)]: 7,
[Symbol(triggerId)]: 0
},
[Symbol(kUniqueHeaders)]: null
}
},
serverPromise: Promise { <pending> }
} The line which causes the error is trying to get the server from
So I've two questions:
Thank you in advance, |
Hi again @lforst , I did another test which solved the issue, but I don't know if is the right implementation. I noticed that the // packages/nextjs/src/utils)/instrumentServer.ts
// Line 31
const wrappedHandlerGetter = async function (this: NextServer): Promise<ReqHandler> {
if (!sdkSetupComplete) {
// NEW --> Await for the server promise
await this.serverPromise;
// stash this in the closure so that `makeWrappedReqHandler` can use it
liveServer = this.server;
const serverPrototype = Object.getPrototypeOf(liveServer);
... After adding that line, the server is working again. |
Ah thank you so much for debugging this. I think you might be correct in your assumptions and we need to somehow I am still wondering why I can't reproduce this - maybe it's a race condition. As for your questions:
I would suggest literally ripping out everything related to Sentry but I don't think this is necessary anymore since you probably identified the issue.
Looking at Next.js' code it doesn't seem like they changed it to |
I opened a PR #6072 that should address this (not yet sure if we're gonna merge it). I opted not to await Instead we're simply awaiting |
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.16.0
Framework Version
7.16.0
Link to Sentry event
No response
Steps to Reproduce
We upgraded to Nextjs 13 and
@sentry/nextjs
to7.16.0
yesterday and started to see this in CircleCI on Cypress job:Expected Result
No errors so Cypress doesn't exit
Actual Result
The text was updated successfully, but these errors were encountered: