next.js: [Next.js 9.0.2] Shallow rendering issue: App cannot be invoked without 'new'
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
- Run
npm install - Run
npm run test - 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

System information
- OS: MacOS 10.14.5 / Windows 10.0.17763 Build 17763
- Version of Next.js: 9.0.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (3 by maintainers)
after i removed the preset-env in presets, all i had in .babelrc was
and it didn’t work
After that i changed to
and it works 👍
Never mind, removing
"@babel/preset-env"from"presets"solve this issue.It is now working fine with the latest canary (9.0.3-canary.6 in my case) and a
.babelrclike so:Same issue in 9.0.3 not happen in 9.0.2
That’s @huv1k solution for now (thank you): “We updated our build to use modern javascript with esmodules in this PR (https://github.com/zeit/next.js/pull/7014). There is a problem that node doesn’t support it yet so you need to use for your tests current node. You can achieve this with this .babelrc:“
This also worked for me, I replaced
["@babel/preset-env", { "targets": "> 0.5% in US" } ]with
["next/babel", { "preset-env": { "targets": "> 0.5% in US" } }]Just a data point, I was able to resolve this issue with unit testing a custom
_app.jsby giving myAppsubclass a no-opconstructor:The latest canary didn’t work for me, but the following did: