在使用NextJS的独立服务器时,重新验证选项似乎不起作用。
我得到了这个:
return {
props: {
page,
},
revalidate: 60,
};
我有以下NextJS配置:
{
output: "standalone",
reactStrictMode: true,
swcMinify: true,
i18n: {
locales: ["default", "en", "nl", "fr"],
defaultLocale: "default",
localeDetection: false,
},
trailingSlash: true,
}
我使用下面的docker文件来创建一个容器:
# Install dependencies only when needed
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# 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
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
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"]
我自己尝试了很多东西,但都不起作用,在互联网上,我一直遇到你必须在NextJS服务器上运行,但如果我是正确的,这就是你在独立运行它时所做的。
1条答案
按热度按时间6za6bjd01#
深入研究了这个问题,发现了更多的错误。发现next/image组件的默认加载程序使用squoosh,因为它安装速度快,适合开发环境。但是对于使用输出的生产环境:“单机”,你必须安装sharp。
所以我跑了
这个错误不再发生了。但是我的内容仍然没有更新。因为我不能让这个工作,我需要继续我 checkout 的项目按需重新验证。在这里阅读更多信息:https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration
所以我现在做的是:
1.在我NextJS解决方案中创建一个API端点以重新验证。
1.使用CMS中的webhook调用该API端点
这对我来说很有用。我现在可以在我的CMS中更新一些东西,webhook被触发,然后我得到了一个新的新的构建页面!
在我看来,这是一个更好的解决方案,因为:
所以我很高兴,它没有工作,并与一点额外的努力,我得到了一个更好的解决方案!
希望这能帮到别人。