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.

[build]: n.end is not a function

See original GitHub issue

Hello everyone, I’ve been trying to use this package to protect some of our under development pages but I’m running into an issue with next optimization step.

The package versions I’m using are

"next": "9.4.4",
"nextjs-basic-auth-middleware": "^0.1.0",

The error comes from an attempt by next to optimize the page

Creating an optimized production build

Compiled successfully.

Automatically optimizing pages ...
Error occurred prerendering page "/new". Read more: https://err.sh/next.js/prerender-error
TypeError: n.end is not a function

My code is as follows:

import Document, { DocumentContext, DocumentInitialProps } from 'next/document'
import basicAuthMiddleware from 'nextjs-basic-auth-middleware'

const credentials = process.env.BASIC_AUTH_CREDENTIALS.split(':')

class MyDocument extends Document {
  static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> {
    await basicAuthMiddleware(ctx.req, ctx.res, {
      users: [{ name: credentials[0], password: credentials[1] }],
      includePaths: ['/new'],
    })

    const initialProps = await Document.getInitialProps(ctx)
    return initialProps
  }
}

export default MyDocument

It seems that the call to basicAuthMiddleware terminates/ends the response which may be used by the call to getInitialProps?

I’ve attempted at reordering the calls to see if that’s the case, but I havent had any luck. One of my subpages is also using the getStaticProps, but removing it doesnt fix the build.

Edit: I realize I forgot to write that process.env.BASIC_AUTH_CREDENTIALS are set at build time, so that’s not a potential source of the error

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jchiattcommented, Dec 15, 2020

@OZZlE @afzalsayed96 @JonasBa I went ahead and rolled my own basic auth package: https://www.npmjs.com/package/nextjs-basic-auth

(It also requires opting out of static generation, unfortunately)

1reaction
OZZlEcommented, Mar 16, 2021

I’m fine with opting out of SSG, we are caching our website in Fastly anyway but what I wrote earlier was that SSR wouldn’t work properly so for us ‘nextjs-basic-auth’ sounds quite interesting! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building: loadReposFromCache(...).error is not a function ...
There are a couple of issues in the build code for that project. ... I forked the project from karljacuncha's answer and changed...
Read more >
JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly.
Read more >
How to solve the "is not a function" error in JavaScript
Let's look at how I got it. JS does not see a semicolon after require(), and we start a line with a (...
Read more >
Declare function name, inputs, and outputs - MATLAB function
This MATLAB function declares a function named myfun that accepts inputs x1,...,xM and returns outputs y1,...,yN.
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
The processing of functions continues until the stack is once again ... A good practice to follow is to make message processing short...
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