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.

Next 11.1.2 throws `TypeError: DocumentComponent.renderDocument is not a function`

See original GitHub issue

🐛 Bug Report

Using next-page-tester 0.28.0 with next 11.1.2 (and possibly 11.1.1?) throws the following error with useDocument: true:

    TypeError: DocumentComponent.renderDocument is not a function

      4 | describe("404 page", () => {
      5 |   it("has a 404 status code", async () => {
    > 6 |     const { render } = await getPage({ route: "/asdf1234", useDocument: true })
        |                        ^
      7 |     render()
      8 |     expectStatusCode(404)
      9 |   })

      at node_modules/next-page-tester/dist/_document/render.js:96:34
      at Object.executeAsIfOnServer (node_modules/next-page-tester/dist/server.js:33:16)
      at getPage (node_modules/next-page-tester/dist/getPage.js:70:31)
      at Object.<anonymous> (__tests__/pages/404.js:6:24)

It looks like it’s reaching this line of code https://github.com/toomuchdesign/next-page-tester/blob/bbde6b3714805c3e2d002f390ea28fa25aa6f61e/src/_document/render.tsx#L151

But the renderDocument function was deleted in this commit 😦

https://github.com/vercel/next.js/commit/08a24780b01608e16b7733d31bda2aaf36fd1750#diff-5d810eb5cd68f6a6a3597e5472015f0c199e21d97cdabc9f7d5ac3fa85adc369L179

Reproduction

I’m guessing it’s trivial enough to bump your next version and see your tests fail

Expected behavior

No errors 😃

Jest patch

Have you patched Jest as described here?

  • yes
  • no, because I’m using Jest 27

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 11.4
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 15.11.0 - ~/.nvm/versions/node/v15.11.0/bin/node
    Yarn: 1.22.5 - /opt/homebrew/Cellar/yvm/4.1.1/shim/yarn
    npm: 7.6.0 - ~/.nvm/versions/node/v15.11.0/bin/npm
  npmPackages:
    jest: ^27.0.0 => 27.0.4 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
toomuchdesigncommented, Oct 11, 2021

Hi @thepuzzlemaster, thanks for pinging us. #268 is a GH issues targeting useDocument option re-enabling.

1reaction
toomuchdesigncommented, Sep 23, 2021

I’ve spent a few few hours on the topic: I could get document rendering to work again with still 3 red tests (of which one concerning head elements update).

Since I won’t be able to spend so much time on this, I will try to release a working breaking version with useDocument option disabled (#267).

Current document rendering implementation heavily relies on next.js internal files. A different approach might consist of re-implementing the minimum document rendering functionality with as little as possible dependencies toward next.js. If possible 😃

In the meanwhile I’ll be happy to support anybody who wanted to give it a try. PR #264 is a good starting point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NExt JS v11.1.2 Build issues - TypeError: c.props.href. ...
In my particular case I'm populating the href for the favicon with a CMS (sanity.io), and the function that generated that resource was ......
Read more >
Advanced Features: Custom `Document`
React components outside of <Main /> will not be initialized by the browser. Do not add application logic here or custom CSS (like...
Read more >
Server-side rendered styled-components with Nextjs
I've recently worked on setting up Next.js with styled-components, ... ://github.com/zeit/next.js/#user-content-custom-document) component ...
Read more >
Getting start with Next.js Framework for server-rendered ...
The aim is to support “shadow CSS” resembling of Web Components, which unfortunately do not support server-rendering and are JS-only.
Read more >
ESP_MDF release/v1.0 mqtt_example root node restart ...
Next 11.1.2 throws `TypeError: DocumentComponent.renderDocument is not a function`, 7, 2021-09-22, 2022-10-07.
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