'NextJS collecting page data fails with status code 500
I have a NextJS application which builds an optimised front end. npm run build is now throwing this error:
> [email protected] build C:\git\MyApp\MyApp-UI\src
> next build
info - Loaded env from C:\git\MyApp\MyApp-UI\src\.env.local
info - Loaded env from C:\git\MyApp\MyApp-UI\src\.env.production
(node:15540) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
info - Checking validity of types
info - Creating an optimized production build
info - Compiled successfully
When it gets to this point I see this:
info - Collecting page data ..
But a moment later that line disappears and I see this:
> Build error occurred
Error: Request failed with status code 500
at createError (C:\git\MyApp\MyApp-UI\src\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\git\MyApp\MyApp-UI\src\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\git\MyApp\MyApp-UI\src\node_modules\axios\lib\adapters\http.js:293:11)
at IncomingMessage.emit (events.js:387:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
type: 'Error',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
transformRequest: [ null ],
transformResponse: [ null ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
headers: { Accept: 'application/json', 'User-Agent': 'axios/0.23.0' },
method: 'get',
url: 'http://localhost:8080/api/v1/catalog/en-GB/pages',
data: null,
withCredentials: false
},
status: 500
}
info - Collecting page data .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
The package.json contains this:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint ./ --ext js,jsx,ts,tsx",
"export": "next export",
"gzip": "gzipper compress --gzip-level 9 --verbose --output-file-format [filename].[ext] ./out ./zipped",
"sitemap": "node ./sitemap-generator/sitemap-gen.js",
"sitemap-index": "node ./sitemap-generator/sitemap-index-gen.js"
},
The URL at 8080 which provides the build-time data returns sensible content when I drop it into a browser. As far as I can see, there is no error there.
The basic question is, what would be causing this and where should I look to identify the source?
If this is something to do with the NODE_TLS_REJECT_UNAUTHORIZED environment variable, where/what do I need to adjust and what is that? (I can't find that variable in the solution.)
Solution 1:[1]
Turns out there was an error in the solution which was being called but due to errors being ignored I had not seen it get caught in the debugger.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt W |
