-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared App from module cannot be invoked without 'new'
#8358
Comments
Maybe this will help. |
@thundermiracle hmm I'm not really understanding that explanation. Seems like that would imply any modules that I import in For example, if I instead import a component from a shared module, that works fine: import React from 'react';
import App, { Container } from 'next/app';
+ import { MyComponent } from 'shared-helpers'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<Container>
+ <MyComponent />
<Component {...pageProps} />
</Container>
)
}
}
export default MyApp; It is only an issue for |
A custom App component must be compiled different for the server and client. On the server, you need to emit ES6 Class syntax! Then the client needs to be transformed with the identical preset as your application code. This entails making your custom {
"presets": [
[
"next/babel",
{
"preset-env": {
"modules": "commonjs",
"exclude": ["transform-classes"]
}
}
]
]
} You'll also need to mark |
☝️ by the way, once it's marked non-external you can stop compiling to the |
@Timer Thanks, adding |
I'm curious of what has changed makes the approach different too. |
My guess is that this is related to the TypeScript migration, but I'm not 100% positive about that. |
It's related to our publishing process, we now publish default pages as "modern" code that is later compiled down to the version needed. This reduced bundle sizes for _app etc by quite a bit. |
💯 Was fortunate to have @Timer give me the heads up yesterday. I, for one, welcome an IE11-free browser support matrix 😅 |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
We have several apps who's
_app.js
exports a common structure from a shared module that is a dependency of each app. This has worked well for use with previous versions of next, but is failing under v9.To Reproduce
git clone https://github.com/kinetifex/next-9-app-bug.git cd ./next-9-app-bug npm i npm run build
This will fail with:
# TypeError: Class constructor App cannot be invoked without 'new'
Expected behavior
The app should build fine.
To see this working correctly with
next@8.1.0
, in the same example project:System information
- Browser (if applies) [e.g. chrome, safari]Additional context
I see other issues reporting
App cannot be invoked without 'new'
, but under a different context to what we are experiencing.The text was updated successfully, but these errors were encountered: