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.js 9.0.2] Shallow rendering issue: App cannot be invoked without 'new'

See original GitHub issue

Bug report

Describe the bug

After updating our app from Next.js 7.0.2 to 9.0.2 enzyme’s shallow rendering (same issue with enzyme’s mount) for the custom <App> (_app.is) not working anymore. The local development server is serving the app perfectly fine, though.

For experimental purposes we also tried running our tests with Next.js 8.1.0 and the rendering caused no problems.

To Reproduce

Clone the issue repository: https://github.com/rzschoch/next-9-issues/tree/shallow-issue

  1. Run npm install
  2. Run npm run test
  3. See error: TypeError: Class constructor App cannot be invoked without 'new'

Expected behavior

The test in /src/pagesSpecs/_app.spec.js should be rendered without issues and compared against the existing snapshot (from Next.js 7.0.2).

Screenshots

image

System information

  • OS: MacOS 10.14.5 / Windows 10.0.17763 Build 17763
  • Version of Next.js: 9.0.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
dannypkcommented, Sep 18, 2019

Never mind, removing "@babel/preset-env" from "presets" solve this issue.

after i removed the preset-env in presets, all i had in .babelrc was

   "presets": [
    "next/babel"
  ] 

and it didn’t work

After that i changed to

"presets": [
    [
      "next/babel",
      {
        "preset-env": { "targets": { "node": "current" } }
      }
    ]
  ]

and it works 👍

14reactions
PaxLyjcommented, Aug 23, 2019

Never mind, removing "@babel/preset-env" from "presets" solve this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Next.js 9.0.2] Shallow rendering issue: App cannot ... - GitHub
After updating our app from Next.js 7.0.2 to 9.0.2 enzyme's shallow rendering (same issue with enzyme's mount) for the custom <App> (_app.is) ...
Read more >
TypeError: Class constructor Document cannot be invoked ...
I changed Next.js version to 9.2 and I am having this issue: TypeError: Class constructor App cannot be invoked without 'new' at new...
Read more >
Upgrade Guide - Next.js
Upgrade Guide. Upgrading from 12 to 13. To update to Next.js version 13, run the following command using your preferred package manager: npm...
Read more >
Advanced Features: Custom `App` - Next.js
This new directory has support for layouts, nested routes, and uses Server Components by default. Inside app/ , you can fetch data for...
Read more >
Basic Features: Pages - Next.js
This new directory has support for layouts, nested routes, and uses Server ... Static Generation is not a good idea if you cannot...
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