Skip to content

Module not found: Error: Cannot resolve module 'next/document' #1123

@manuelro

Description

@manuelro

The framework accomplishes a very important milestone: server and client rendering with a single code base, which is great. However, while trying to create a custom <Document> I receive the following error:

Module not found: Error: Cannot resolve module 'next/document'

I just copy-pasted the sample code in the README file.

// ./pages/_document.js
import Document, { Head, Main, NextScript } from 'next/document'

export default class MyDocument extends Document {
  static async getInitialProps (ctx) {
    const props = await Document.getInitialProps(ctx)
    return { ...props, customValue: 'hi there!' }
  }

  render () {
    return (
     <html>
       <Head>
         <style>{`body { margin: 0 } /* custom! */`}</style>
       </Head>
       <body className="custom_class">
         {this.props.customValue}
         <Main />
         <NextScript />
       </body>
     </html>
    )
  }
}

Is next/document bundled with the framework or is this an optional module? Any ideas? The Link and the other components are working fine.

NPM version: 3.10.9
Node version: v6.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions