My NextJS application getting build error in netlify deployment, the issue only occurs when the application contains multiple [slug].js templates. The applications contain 4 slug templates in a different path of /pages folder like the blog, services, etc⦠When I removed all of the slug files and kept only one slug file the build ran successfully. Here below are the errors shown in the build logs.
Cannot read properties of undefined (reading 'map')
Unhandled error during request: TypeError: socialLinks.map is not a function
TypeError: Cannot read properties of undefined (reading 'filename')
But these are code-related errors and I managed it with better error handling. And I only got the errors while taking build by netlify and not in the local dev and build environment.
Also I didnβt make any code changes in the past months, I only update some contents in storyblok which connected with my nextjs app to manage the site contents, so when I change the content and I trigger the build with netlify build hook in storyblok so it will automatically build my app with the latest content. But in last week the builds were not running and I noticed the issue. A couple of months before some time I got the same error and It will solve when I tried with clear cache and deploy site option in netlify deploys. But this time it not working so I improved the error handling in my code and tried in the local dev and build environment itβs working perfectly. I noticed in netlify getting the errors only that contain multiple slug files so itβs something related to a concurrent build issue. Full build logs are added below.
Site ID: 1e56893a-d7d1-48aa-94f2-bcdbafff55e3
My site is an SSG and uses the next build && next export command for the build. also revalidate and fallback are false.
Due to privacy I cannot share the full logs here.
10:51:46 AM: Build ready to start
10:51:49 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
10:51:49 AM: build-image tag: v4.10.1
10:51:49 AM: buildbot version: f7070267d9348624fde5c2d682aa32cc686742a6
10:51:50 AM: Fetching cached dependencies
10:51:50 AM: Starting to download cache of 595.6MB
10:51:56 AM: Finished downloading cache in 6.387842501s
10:51:56 AM: Starting to extract cache
10:51:59 AM: Finished extracting cache in 3.011828867s
10:51:59 AM: Finished fetching cache in 9.502588512s
10:51:59 AM: Starting to prepare the repo for build
10:52:00 AM: Preparing Git Reference refs/heads/main
10:52:00 AM: Parsing package.json dependencies
10:52:01 AM: Starting build script
10:52:01 AM: Installing dependencies
10:52:01 AM: Python version set to 2.7
10:52:01 AM: Started restoring cached node version
10:52:02 AM: Finished restoring cached node version
10:52:02 AM: v16.17.0 is already installed.
10:52:03 AM: Now using node v16.17.0 (npm v8.15.0)
10:52:03 AM: Started restoring cached build plugins
10:52:03 AM: Finished restoring cached build plugins
10:52:03 AM: Attempting ruby version 2.7.2, read from environment
10:52:03 AM: Using ruby version 2.7.2
10:52:03 AM: Using PHP version 8.0
10:52:03 AM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
10:52:03 AM: Started restoring cached yarn cache
10:52:05 AM: Finished restoring cached yarn cache
10:52:05 AM: No yarn workspaces detected
10:52:05 AM: Started restoring cached node modules
10:52:05 AM: Finished restoring cached node modules
10:52:06 AM: Installing NPM modules using Yarn version 1.22.10
10:52:06 AM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
10:52:06 AM: npm WARN config location in the cache, and they are managed by
10:52:06 AM: npm WARN config [`cacache`](http://npm.im/cacache).
10:52:06 AM: yarn install v1.22.10
10:52:06 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
10:52:06 AM: [1/4] Resolving packages...
10:52:06 AM: success Already up-to-date.
10:52:06 AM: Done in 0.23s.
10:52:06 AM: NPM modules installed using Yarn
10:52:06 AM: Started restoring cached go cache
10:52:06 AM: Finished restoring cached go cache
10:52:06 AM: Installing Go version 1.16.5 (requested 1.16.5)
10:52:10 AM: unset GOOS;
10:52:10 AM: unset GOARCH;
10:52:10 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64';
10:52:10 AM: export PATH="/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64/bin:${PATH}";
10:52:10 AM: go version >&2;
10:52:10 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.16.5.linux.amd64.env"
10:52:10 AM: go version go1.16.5 linux/amd64
10:52:10 AM: Installing missing commands
10:52:10 AM: Verify run directory
10:52:11 AM: β
10:52:11 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:11 AM: Netlify Build
10:52:11 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:11 AM: β
10:52:11 AM: β― Version
10:52:11 AM: @netlify/build 27.15.7
10:52:11 AM: β
10:52:11 AM: β― Flags
10:52:11 AM: baseRelDir: true
10:52:11 AM: buildId: 630706e9bf162700083abb85
10:52:11 AM: deployId: 630706e9bf162700083abb87
10:52:11 AM: β
10:52:11 AM: β― Current directory
10:52:11 AM: /opt/build/repo
10:52:11 AM: β
10:52:11 AM: β― Config file
10:52:11 AM: /opt/build/repo/netlify.toml
10:52:11 AM: β
10:52:11 AM: β― Context
10:52:11 AM: production
10:52:12 AM: β
10:52:12 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:12 AM: 1. @netlify/plugin-nextjs (onPreBuild event)
10:52:12 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:12 AM: β
10:52:12 AM: Next.js cache restored.
10:52:12 AM: Not running Next Runtime
10:52:12 AM: β
10:52:12 AM: (@netlify/plugin-nextjs onPreBuild completed in 93ms)
10:52:12 AM: β
10:52:12 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:12 AM: 2. build.command from netlify.toml
10:52:12 AM: ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
10:52:12 AM: β
10:52:12 AM: $ npm run deploy
10:52:13 AM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
10:52:13 AM: npm WARN config location in the cache, and they are managed by
10:52:13 AM: npm WARN config [`cacache`](http://npm.im/cacache).
10:52:13 AM: > abc-website@0.1.0 deploy
10:52:13 AM: > next build && next export
10:52:13 AM: warn - The `target` config is deprecated and will be removed in a future version.
10:52:13 AM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
10:52:13 AM: Browserslist: caniuse-lite is outdated. Please run:
10:52:13 AM: npx browserslist@latest --update-db
10:52:13 AM: Why you should do it regularly:
10:52:13 AM: https://github.com/browserslist/browserslist#browsers-data-updating
10:52:13 AM: info - Checking validity of types...
10:52:13 AM: info - Creating an optimized production build...
10:52:13 AM: Browserslist: caniuse-lite is outdated. Please run:
10:52:13 AM: npx browserslist@latest --update-db
10:52:13 AM: Why you should do it regularly:
10:52:13 AM: https://github.com/browserslist/browserslist#browsers-data-updating
10:52:14 AM: postcss-resolve-url: postcss.plugin was deprecated. Migration guide:
10:52:14 AM: https://evilmartians.com/chronicles/postcss-8-plugin-migration
10:52:14 AM: Browserslist: caniuse-lite is outdated. Please run:
10:52:14 AM: npx browserslist@latest --update-db
10:52:14 AM: Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
10:52:22 AM: warn - Compiled with warnings
10:52:22 AM: ./node_modules/follow-redirects/debug.js
10:52:22 AM: Module not found: Can't resolve 'debug' in '/opt/build/repo/node_modules/follow-redirects'
Did you mean './debug'?
10:52:22 AM: Requests that should resolve in the current directory need to start with './'.
10:52:22 AM: Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
10:52:22 AM: If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
10:52:22 AM: Import trace for requested module:
10:52:22 AM: ./node_modules/follow-redirects/index.js
10:52:22 AM: ./node_modules/axios/lib/adapters/http.js
10:52:22 AM: ./node_modules/axios/lib/defaults.js
10:52:22 AM: ./node_modules/axios/lib/axios.js
10:52:22 AM: ./node_modules/axios/index.js
10:52:22 AM: ./node_modules/storyblok-js-client/dist/index.cjs.js
10:52:22 AM: ./components/Blog/BlogBody.js
10:52:22 AM: ./pages/blog/[slug].js
10:52:22 AM: ./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js?page=%2Fblog%2F%5Bslug%5D&absolutePagePath=private-next-pages%2Fblog%2F%5Bslug%5D.js&absoluteAppPath=private-next-pages%2F_app.js&absoluteDocumentPath=next%2Fdist%2Fpages%2F_document&absoluteErrorPath=private-next-pages%2F_error.js&absolute404Path=private-next-pages%2F404.js&distDir=private-dot-next&buildId=NWg_jUw9Up7gKgbjf4b8I&assetPrefix=&generateEtags=true&poweredByHeader=true&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%22939fcf5fcf5dbab389c43f3f7d4f6cf1%22%2C%22previewModeSigningKey%22%3A%220cae4d58bab0259384ad834dad303cf1fd797364e92c50e5a9f7892a279093f8%22%2C%22previewModeEncryptionKey%22%3A%22c886707eaa3fc213cde7f45136518cb4a1c153e279a7c03d2446b8e8e1cec5bb%22%7D&loadedEnvFiles=W10%3D&i18n=!
10:52:22 AM: info - Collecting page data...
10:52:26 AM: info - Generating static pages (0/301)
10:52:30 AM: The render method must receive an object with a content field, which is an array
10:52:30 AM: The render method must receive an object with a content field, which is an array
10:52:30 AM: The render method must receive an object with a content field, which is an array
10:52:30 AM: The render method must receive an object with a content field, which is an array
10:52:30 AM: The render method must receive an object with a content field, which is an array
10:52:31 AM: info - Generating static pages (75/301)
10:52:32 AM: Unhandled error during request: TypeError: Cannot read properties of undefined (reading 'map')
10:52:32 AM: at Footer (/opt/build/repo/.next/serverless/chunks/35.js:30:58)
10:52:32 AM: at d (/opt/build/repo/.next/serverless/chunks/807.js:21925:498)
10:52:32 AM: at bb (/opt/build/repo/.next/serverless/chunks/807.js:21928:16)
10:52:32 AM: at a.b.render (/opt/build/repo/.next/serverless/chunks/807.js:21934:43)
10:52:32 AM: at a.b.read (/opt/build/repo/.next/serverless/chunks/807.js:21933:83)
10:52:32 AM: at Object.exports.renderToString (/opt/build/repo/.next/serverless/chunks/807.js:21944:138)
10:52:32 AM: at Object.renderPage (/opt/build/repo/.next/serverless/chunks/807.js:17795:46)
10:52:32 AM: at Object.defaultGetInitialProps (/opt/build/repo/.next/serverless/chunks/807.js:17448:51)
10:52:32 AM: at Function.getInitialProps (/opt/build/repo/.next/serverless/chunks/807.js:11371:20)
10:52:32 AM: at Object.loadGetInitialProps (/opt/build/repo/.next/serverless/chunks/807.js:14858:29)
10:52:32 AM: Error occurred prerendering page "/blog/web-application-development-trends". Read more: https://nextjs.org/docs/messages/prerender-error