I'm encountering random occurrences of the .next/BUILD_ID file not being generated on a successful build. The issues started 3 days ago and I've been rebuilding the same commit multiple times to try and identify why.
The build is being done within the docker base node:20-alpine3.17 and is transpiling typescript along with using yarn in place of the normal npm calls. I haven't encountered any build errors when the BUILD_ID file is missing and when the container is launched it fails on start up because of the verification that next is doing to ensure the .next folder has been built with the optimizations for production.
What would cause a next build to succeed but not produce a BUILD_ID file in the .next folder?
Dockerfile
FROM node:20-alpine3.17
RUN apk -U upgrade
WORKDIR /app
COPY source.tar.gz ./
RUN tar -xhzf source.tar.gz --strip-components=1 && rm -f source.tar.gz
RUN npm update -g npm node && npm install --global yarn --force
RUN yarn && yarn compile-ts && yarn build
RUN rm -rf /app/.next/cache
package.json
{
"scripts": {
"production": "cross-env NODE_ENV=production npm start",
"build": "next build",
"start": "next start",
"compile-ts": "tsc"
},
"devDependencies": {
"@simbathesailor/use-what-changed": "^2.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.1.2",
"@types/node": "^20.2.5",
"@types/nprogress": "^0.2.0",
"@types/react": "^18.2.8",
"@types/react-dom": "^18.2.4",
"@types/react-test-renderer": "^18.0.0",
"@types/styled-components": "^5.1.26",
"@welldone-software/why-did-you-render": "^7.0.1",
"cross-env": "^7.0.3",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"eslint": "8.37.0",
"eslint-config-next": "13.3.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-watch": "^8.0.0",
"jest": "^29.1.2",
"jest-environment-jsdom": "^29.1.2",
"jest-junit": "^15.0.0",
"prettier": "^2.7.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-test-renderer": "^18.2.0",
"scheduler": "^0.23.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.3"
},
"dependencies": {
"@next/bundle-analyzer": "^13.3.0",
"css-loader": "^6.7.3",
"dayjs": "^1.11.7",
"device": "^0.3.12",
"express": "^4.18.2",
"formik": "^2.2.9",
"html-react-parser": "^3.0.8",
"isomorphic-unfetch": "^4.0.2",
"minify-css-string": "1.0.0",
"modern-normalize": "^1.1.0",
"next": "^13.4.1",
"next-images": "^1.8.4",
"next-redux-wrapper": "^8.1.0",
"nodemon": "^2.0.20",
"nookies": "^2.5.2",
"nprogress": "^0.2.0",
"pure-react-carousel": "^1.30.1",
"react": "18.2.0",
"react-avatar-editor": "13.0.0",
"react-dom": "18.2.0",
"react-dropzone": "^14.2.3",
"react-grid-system": "^8.1.8",
"react-redux": "^8.0.5",
"react-responsive": "^9.0.2",
"react-scrolllock": "^5.0.1",
"react-share": "^4.4.1",
"react-sticky-table": "^5.1.11",
"react-stickynode": "^4.1.0",
"react-toastify": "^9.1.1",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"styled-components": "^5.3.6",
"uuid": "^9.0.0",
"yarn": "^1.22.19"
},
"peerDependencies": {
"@next/bundle-analyzer": "^12.3.1"
},
"resolutions": {
"styled-components": "^5",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"@types/styled-components": "^5.1.26"
}
}
2 Answers 2
Start server by using npm run dev not npm run start . Or make a build npm run build . More info here https://nextjs.org/docs/messages/next-export-no-build-id
1 Comment
The default memory limit may be causing the build to be silently (!) interrupted by OOM during the Next.js build.
You may need to increase the memory limit during the build via NODE_OPTIONS=--max_old_space_size=4096 npm run build as suggested by https://github.com/vercel/next.js/discussions/58523#discussioncomment-8286858
This helped resolve our "random" build failures via increasing the memory limit to 16 GiB by RUN NODE_OPTIONS=--max_old_space_size=16384 npm run build.