-
Notifications
You must be signed in to change notification settings - Fork 319
The default export is not a React Component in page #80
Comments
Hi, I replicated your example and everything is working as expected, No errors whatsoever in pages Try updating packages, or remove |
I had a similar problem with TypeScript and I had to change my {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
// ...
} |
For the record, if you are using
|
It only works for me when I set module to "esnext" and create a separate tsconfig.json for my custom server.ts with module "commonjs". But then I'm still left with the problem that running my tests in jest doesn't work, because the jest run is done in node so it would require commonjs but then I can't import the files that are compiled to esnext. I'm not using next-typescript though, maybe that will fix it. No time to test it this moment though. |
@timneutkens yes, that's what I hadn't had time yet to test. Turns out for some reason I still can't get it to work in my project. Which lead me to see vercel/next.js#3663 which is closed but other people have the same problem as well. It works fine in the example, but I cannot get my actual project to run tests properly. It's always either "unexpected token import" or "unexpected token" at <MyComponent> (fails to transpile tsx?). There is something really wrong there and I'm ~65% sure it has to do with esnext default imports/exports. But I think next.js issue #3663 is the one where this should be continued. |
Are you exporting the default component? Export default componente.g. as a class class Homepage extends React.Component{
render(){
return (<main> Hello World </main>);
}
}
export default HomePage; or as a pure function: const HomePage = () => (
<main>Hello World</main>
)
export default HomePage ConfigPS: My
|
This solved my issue, just forgot to add my export at the bottom. |
TLDR: I am using For anyone finding themselves here - I got caught on this error as I had extended the tsconfig recommended base rather then the node12 base Once I did this nextjs asked me to add a couple more things like |
Next5TsAsyncProblem
"target": "esnext",
"module": "esnext",
if tsconfig.json use above config that server part can't use import
so I setup like
"target": "es2015",
"module": "commonjs",
but When I use "async getInitialProps" that will show error
if remove async will be ok
how to fix this?
https://github.com/polo13999/Next5TsAsyncProblem
The text was updated successfully, but these errors were encountered: