question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nextjs 13 / Cypress: TypeError: Cannot convert undefined or null to object

See original GitHub issue

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 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:closed
  • Created a year ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lforstcommented, Oct 27, 2022

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) when getServerRequestHandler 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.

1reaction
lforstcommented, Oct 27, 2022

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:

How I can disable fully the @sentry/nextjs library to prevent this error to appear and don’t block my feature? Should I delete the sentry.client.config.ts and sentry.server.config.ts files too?

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.

By other side, do you know if there’re any changes on Nextjs 13 that changed the property from this.server to this.httpServer?

Looking at Next.js’ code it doesn’t seem like they changed it to this.httpServer.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found