question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'url' of undefined

See original GitHub issue

I created a _document.js to make a Custom Document, per https://nextjs.org/docs/advanced-features/custom-document

I’m getting the error TypeError: Cannot read property 'url' of undefined

Here’s my pages/_document.js:

import Document, { Html, Head, Main, NextScript } from 'next/document'
import basicAuthMiddleware from 'nextjs-basic-auth-middleware'



class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx)
    await basicAuthMiddleware(ctx["req"], ctx["res"], {})
    return { ...initialProps }
  }

  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
kkomelincommented, Mar 17, 2021

same with next@10.0.8

5reactions
webdebcommented, Nov 21, 2020

same issue with next@10.0.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'url' of undefined ...
Set a breakpoint in the console and look at the results being returned. > data.responseData.results [Object, Object, Object, Object].
Read more >
What to do about “Cannot read property 'url' of undefined”
You'll need to provide more specific code for further help, but this error means you are trying to access a property on a...
Read more >
TypeError: Cannot read property 'url' of undefined - JavaScript
Hi there, I'm getting a TypeError: Cannot read property 'url' of undefined error when trying to render images in one of my components....
Read more >
Cannot read property 'url' of undefined · Issue #3837 - GitHub
Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found