[build]: n.end is not a function
See original GitHub issueHello 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:
- Created 3 years ago
- Comments:10 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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)
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! 😃