NextJS 生产版本不创建 .next/BUILD_ID

Aar*_*ron 7 node.js npm yarnpkg next.js

我遇到了.next/BUILD_ID在成功构建时随机出现的文件未生成的情况。这些问题是在 3 天前开始的,我已经多次重建同一个提交来尝试找出原因。

构建是在 docker 基础上完成的node:20-alpine3.17,并且正在转译 typescript 并使用 Yarn 代替正常的 npm 调用。当文件丢失时,我没有遇到任何构建错误,BUILD_ID并且当容器启动时,它启动失败,因为 next 正在进行验证,以确保 .next 文件夹已通过生产优化构建。

什么会导致下一个构建成功但不会BUILD_ID.next文件夹中生成文件?

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
Run Code Online (Sandbox Code Playgroud)

包.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"
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 3

使用 npm run dev 而不是 npm run start 启动服务器。或者进行构建 npm run build 。更多信息请参见 https://nextjs.org/docs/messages/next-export-no-build-id