Nextjs 13 / Cypress: TypeError: Cannot convert undefined or null to object
See original GitHub issueIs 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?
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
to 7.16.0
yesterday and started to see this in CircleCI on Cypress job:
/home/circleci/project/node_modules/@sentry/nextjs/cjs/utils/instrumentServer.js:77
const serverPrototype = Object.getPrototypeOf(liveServer);
^
TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at NextServer.wrappedHandlerGetter (/home/circleci/project/node_modules/@sentry/nextjs/cjs/utils/instrumentServer.js:77:38)
at /home/circleci/project/node_modules/next/dist/server/next.js:78:47
at Server.<anonymous> (/home/circleci/project/node_modules/next/dist/server/lib/start-server.js:17:16)
at Server.emit (node:events:513:28)
at Server.emit (node:domain:489:12)
at parserOnIncoming (node:_http_server:998:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
Error: server closed unexpectedly
at ChildProcess.onClose (/home/circleci/project/node_modules/start-server-and-test/src/index.js:75:14)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1100:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
Expected Result
No errors so Cypress doesn’t exit
Actual Result
/home/circleci/project/node_modules/@sentry/nextjs/cjs/utils/instrumentServer.js:77
const serverPrototype = Object.getPrototypeOf(liveServer);
^
TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at NextServer.wrappedHandlerGetter (/home/circleci/project/node_modules/@sentry/nextjs/cjs/utils/instrumentServer.js:77:38)
at /home/circleci/project/node_modules/next/dist/server/next.js:78:47
at Server.<anonymous> (/home/circleci/project/node_modules/next/dist/server/lib/start-server.js:17:16)
at Server.emit (node:events:513:28)
at Server.emit (node:domain:489:12)
at parserOnIncoming (node:_http_server:998:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
Error: server closed unexpectedly
at ChildProcess.onClose (/home/circleci/project/node_modules/start-server-and-test/src/index.js:75:14)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1100:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Cannot convert undefined or null to Object in JavaScript
The "Cannot convert undefined or null to Object" error occurs when we pass a null or an undefined value to a function that...
Read more >Next.js - TypeError: Cannot convert undefined or null to object
I'm getting this 'TypeError: Cannot convert undefined or null to object' error when trying to run my project locally (screenshot below).
Read more >Changelog - Cypress Documentation
Fixed a regression introduced in Cypress 12 where cy.get() would ignore a null value for the withinSubject option. Fixes #25104.
Read more >typeerror: cannot convert object to primitive value - You.com
This issue seems to be related to jQuery 3.5.0. It is a breaking change that affects many plugins. Temporarily reverting to a previous...
Read more >TypeError: "x" is not a function - JavaScript - MDN Web Docs
Maybe there is a typo in the function name? Maybe the object you are calling the method on does not have this function?...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I opened a PR #6072 that should address this (not yet sure if we’re gonna merge it). I opted not to await
serverPromise
because that field might potentially not be defined (at least typing wise) whengetServerRequestHandler
is called:https://github.com/vercel/next.js/blob/0beed3563cdab846fd6b683f1ed5586de3e7d96d/packages/next/server/next.ts#L42
Instead we’re simply awaiting
getServer
which seems safe-ish.Ah thank you so much for debugging this. I think you might be correct in your assumptions and we need to somehow
await
the server.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
this.httpServer
.