with-typescript-styled-components
Using the with-typescript-styled-components example I am trying to change the title of the root page, using the Next.js provided "Head" component (import { Head } from 'next/document'
)
When trying to start the app, whether through yarn dev
or yarn build
then yarn start
, I receive the error "TypeError: Cannot destructure property styles
of 'undefined' or 'null'."
yarn
import React from 'react'
import styled from 'styled-components'
import { Head } from 'next/document';
const Title = styled.h1`
color: red;
font-size: 50px;
`
export default () => <>
<Head><title>This is the title</title></Head>
<Title>My page</Title>
</>
yarn dev
styles
of 'undefined' or 'null'."After running the app, and navigating to localhost:3000, I should be presented with a page with the text "My page" and the tab in chrome should read "This is the title".
"next": "latest"
)Please let me know if you require additional context, or if I have created this bug report incorrectly.
I'm getting the same issue in a project i've just updated to v9 (not using typescript or styled components), i can get titles working by changing the import to:
import Head from 'next/head';
Hi, the Head
export from next/document
is only supposed to be used in pages/_document
. In other pages you are supposed to use next/head
. See the Populating Head section of our docs for more info.
Hi, the
Head
export fromnext/document
is only supposed to be used inpages/_document
. In other pages you are supposed to usenext/head
. See the Populating Head section of our docs for more info.
I'm getting the same issue in a project i've just updated to v9 (not using typescript or styled components), i can get titles working by changing the import to:
import Head from 'next/head';
Ahh I see, thank you both, that did the trick!
That's also happened to me. The 'auto-import' has imported Head from next/document as a destructing component.
Most helpful comment
Hi, the
Head
export fromnext/document
is only supposed to be used inpages/_document
. In other pages you are supposed to usenext/head
. See the Populating Head section of our docs for more info.