我正在尝试使用NextJS独立模式和PNPM创建生产Dockerfile。
在next.config.js
中,我有输出配置:
experimental: {
outputStandalone: true,
outputFileTracingRoot: path.join(__dirname, '../../'),
},
在Dockerfile中,我使用了多阶段构建:
# BUILD STEP
FROM node:16.13-alpine as landing-builder
WORKDIR /dml-sdk
COPY ./pnpm-workspace.yaml .
COPY ./pnpm-lock.yaml .
COPY ./tsconfig.base.json .
COPY ./package.json .
COPY ./apps/landing ./apps/landing
RUN apk --no-cache add curl
RUN apk --no-cache add git
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@6
RUN pnpm config set store-dir .pnpm-store
RUN pnpm i
RUN pnpm build
# RUNNER STEP
FROM node:16.13-alpine as landing-runner
WORKDIR /dml-sdk
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
COPY --from=landing-builder /dml-sdk/apps/landing/public ./public
COPY --from=landing-builder --chown=nextjs:nodejs /dml-sdk/apps/landing/.next/standalone ./
COPY --from=landing-builder --chown=nextjs:nodejs /dml-sdk/node_modules ./node_modules
ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT 3010
EXPOSE 3010
WORKDIR /dml-sdk/apps/landing
CMD ["node", "server.js"]
出于某种原因,我犯了一个错误:
landing | Error: Cannot find module 'next/dist/server/next-server'
landing | Require stack:
landing | - /powerplay-sdk/apps/landing/server.js
看起来下一个服务器没有捆绑在standalone
目录中,并且行:
const NextServer = require('next/dist/server/next-server').default
链接到根节点_模块,而不是/dml-sdk/standalone/apps/landing/node_modules
:
node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/next-server.d.ts
是否可以在BUILD步骤中禁用下一个服务器链接,以便standalone
node_modules包含next-server
?
1条答案
按热度按时间zlhcx6iw1#
我猜有问题
它会将
standalone
文件/文件夹从WORKDIR /dml-sdk
复制到您的工作目录。所以你得到/dml-sdk/standalone
。尝试下一或
或