我正在尝试部署我的下一个13应用程序。我没有看到任何错误,而建设。当我尝试加载应用程序时,只有HTML显示出来,它显示404错误的Js,CSS和图像(如在网络选项卡中看到的)。
默认情况下,它试图从_next文件夹加载(并且此路径不存在)
例如:http://localhost:3000/_next/static/chunks/522-b7eb9fb4e38abfae.js
和图像直接
例如:http://localhost:3000/assets/login.png
可惜我不能发布src代码。
我什么都试过了。任何帮助都很感激。
文件夹结构
My-app
|_ public
|_ assets/
|_[all my images]
|_ nodemodules
|_ .next
|_ out
|_ src
|_ app
|_ Dockerfile
|_ next.config.js
|_ package.json
下面是使用
next.config.js
module.exports = {
basePath: "",
output: "standalone",
experimental: {
appDir: true,
},
images: {
domains: [
"localhost",
"localhost:3001",
"my-exapmle-domain.com",
],
},
};
dockerfile
#Using a different image, below is just an example
FROM node:16_alpine-3.16 AS prebuild
USER root
WORKDIR /app
ARG env
ENV NODE_ENV=${env}
RUN apk add --no-cache libc6-compat
RUN apk add --update npm
COPY package.json ./
COPY package-lock.json ./
RUN npm i --legacy-peer-deps
COPY . .
RUN npm run build
#Using a different image, below is just an example
FROM node:16_alpine-3.16
USER root
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED 1
ENV UID=10101
ENV GID=10101
## create & switch to non-root user
RUN apk add shadow
RUN /usr/sbin/groupadd -g ${GID} docker
RUN /usr/sbin/useradd -s /bin/sh -g ${GID} -u ${UID} limsuinext
USER 10101
COPY --from=prebuild /app/next.config.js ./
COPY --from=prebuild /app/package.json ./package.json
COPY --from=prebuild /app/.next ./.next
COPY --from=prebuild /app/node_modules ./node_modules
COPY --from=prebuild /app/public/ ./public
COPY --from=prebuild --chown=10101 /app/.next/standalone ./
COPY --from=prebuild --chown=10101 /app/.next/static ./.next/static
COPY --from=prebuild --chown=10101 /app/.next/static ./.next/standalone/static
COPY --from=prebuild --chown=10101 /app/.next/out ./.next/standalone/out
# Fire up node server
ENV PORT 3001
EXPOSE 3001
# CMD ["node", ".next/standalone/server.js"] Old approach
CMD ["node", "server.js"]
package.json
name: "my-app",
version: "0.1.0",
private: true,
scripts: {
"dev": "PORT=3001 npx next dev",
"build": "npx next build",
"start": "PORT=3001 next start",
"lint": "next lint"
},
dependencies: {...},
devDependencies: {...}
1条答案
按热度按时间gblwokeq1#
修复方法是手动复制dockerfile中的_next文件夹
对于js和cssCOPY --from=builder --chown=10101 /app/.next ./_next
对于镜像COPY --from=builder --chown=10101 /app/public ./public