首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图将对Docker的支持添加到现有的NextJS项目中,但得到"stat /..next/standalone: file不存在“错误

试图将对Docker的支持添加到现有的NextJS项目中,但得到"stat /..next/standalone: file不存在“错误
EN

Stack Overflow用户
提问于 2022-03-08 18:40:46
回答 2查看 3K关注 0票数 12

我按照本指南将Docker支持添加到我现有的NextJS + TypeScript项目中,并部署到Google:https://github.com/vercel/next.js/tree/canary/examples/with-docker

但是,构建容器步骤:

代码语言:javascript
复制
docker build -t nextjs-docker .

一直失败,因为它给了我一个错误,即"stat /..next/standalone: file不存在“错误。

我查看了我的.next文件夹,没有生成独立的文件,这就是为什么我会得到这个错误。如何创建这个..next/独立文件?

我的next.config.js文件如下所示:

代码语言:javascript
复制
module.exports = {
  eslint: {
    ignoreDuringBuilds: true,
  },
  experimental: {
    outputStandalone: true
  }
}

我的Dockerfile如下所示:

代码语言:javascript
复制
# Install dependencies only when needed
FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json package-lock.json tsconfig.json ./ 
RUN npm ci

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN npm run build

# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size 
# https://nextjs.org/docs/advanced-features/output-file-tracing

# Following line is giving me the error
# NOTE: I can not just comment out this line because it will give an error later that "Cannot find module '/app/server.js'"
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

我的.next文件夹看起来如下:

代码语言:javascript
复制
- .next
  - cache
  - server
  - static
  - traces
  - BUILD_ID
  - build-manifest.json
  - export.marker.json
  - images-manifest.json
  - prerender-manifest.json
  - react-loadasble-manifest.json
  - required-server-files.json
  - routes-manifest.json
  - trace

我的理解是:

代码语言:javascript
复制
experimental: {
  outputStandalone: true
}

对于next.config.js文件,然后运行npm run build将创建..next/独立文件,但似乎不起作用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-03-09 08:21:32

如果这对其他人有帮助,我的"next“版本被设置为"^11.1.0”,而独立文件夹只适用于"next“版本"^12.1.0”和更高版本。更新我的package.json解决了问题!

票数 7
EN

Stack Overflow用户

发布于 2022-10-01 02:18:25

我修正了在下一个配置文件中添加输出独立的问题。

代码语言:javascript
复制
filename : next.config.js

代码:

代码语言:javascript
复制
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  swcMinify: true,
  output: "standalone",
};
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71400016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档