Building a Nuxt 3 app inside Docker
See original GitHub issueEnvironment
Host machine: Nuxt CLI v3.0.0-27235451.ece0e01 RootDir: /XXX/web Nuxt project info:
- Operating System:
Darwin
- Node Version:
v16.11.0
- Nuxt Version:
3-3.0.0-27235451.ece0e01
- Package Manager:
Yarn
- Bundler:
Webpack
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Inside docker building container: Nuxt CLI v3.0.0-27235451.ece0e01 RootDir: /app Nuxt project info:
- Operating System:
Linux
- Node Version:
v14.18.1
- Nuxt Version:
3-3.0.0-27235451.ece0e01
- Package Manager:
Yarn
- Bundler:
Webpack
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Docker version: Docker version 20.10.8, build 3967b7d
MacOs Big Sur version (intel based): 11.6
Describe the bug
When building a Nuxt 3 app using a Dockerfile the build fails because it can’t load some plugins (see logs below). I don’t know if I’m doing something wrong because something drastically changed since Nuxt 2 or if it is a bug.
Reproduction
-
create a new Nuxt 3 project:
npx nuxi init .
-
install this project dependencies
yarn install
(at this stage it is working on the host machine without docker)
- Create a file Dockerfile containing the following content:
FROM node:lts as builder
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --prefer-offline --pure-lockfile --non-interactive --production=false
COPY . .
# The following line was just added for opening the issue
RUN npx nuxi info # this was added
RUN yarn build
FROM node:lts-alpine
WORKDIR /app
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/yarn.lock ./yarn.lock
RUN NODE_ENV=production yarn install --pure-lockfile --non-interactive --production=true
COPY --from=builder /app/.output ./.output
ENV HOST 0.0.0.0
EXPOSE 3000
ENTRYPOINT [ "yarn", "start" ]
- Create a .gitignore file containing:
.nuxt
.output
node_modules
Dockerfile
README.md
-
start building the image
docker build . -t nuxt-web:latest
-
get an error (see logs below)
Additional context
the build command work on the host machine just fine and create the .output folder
Logs
[+] Building 5.6s (15/19)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/node:lts-alpine 2.1s
=> [internal] load metadata for docker.io/library/node:lts 0.0s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [builder 1/7] FROM docker.io/library/node:lts 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 357B 0.0s
=> [stage-1 1/6] FROM docker.io/library/node:lts-alpine@sha256:a251de4db0e0632446c0ba62adbe1e37ff148a53732e4574d2ed0f5462cc4407 0.0s
=> CACHED [stage-1 2/6] WORKDIR /app 0.0s
=> CACHED [builder 2/7] WORKDIR /app 0.0s
=> CACHED [builder 3/7] COPY package.json yarn.lock ./ 0.0s
=> CACHED [builder 4/7] RUN yarn install --prefer-offline --pure-lockfile --non-interactive --production=false 0.0s
=> [builder 5/7] COPY . . 0.0s
=> [builder 6/7] RUN npx nuxi info 2.0s
=> ERROR [builder 7/7] RUN yarn build 1.4s
------
> [builder 7/7] RUN yarn build:
#15 0.330 yarn run v1.22.15
#15 0.351 $ nuxt build
#15 0.418 Nuxt CLI v3.0.0-27235451.ece0e01
#15 0.958 ✔ Generated nuxt.d.ts
#15 1.309
#15 1.309 ERROR [vite:load-fallback] Could not load /app/node_modules/nuxt3/dist/app/node_modules/nuxt3/dist/meta/runtime/lib/vueuse-head.plugin (imported by virtual:/app/.nuxt/plugins/client.mjs): ENOENT: no such file or directory, open '/app/node_modules/nuxt3/dist/app/node_modules/nuxt3/dist/meta/runtime/lib/vueuse-head.plugin'
#15 1.309
#15 1.309
#15 1.309 ERROR Could not load /app/node_modules/nuxt3/dist/app/node_modules/nuxt3/dist/meta/runtime/lib/vueuse-head.plugin (imported by virtual:/app/.nuxt/plugins/client.mjs): ENOENT: no such file or directory, open '/app/node_modules/nuxt3/dist/app/node_modules/nuxt3/dist/meta/runtime/lib/vueuse-head.plugin'
#15 1.309
#15 1.309
#15 1.309
#15 1.338 error Command failed with exit code 1.
#15 1.338 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
executor failed running [/bin/sh -c yarn build]: exit code: 1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top GitHub Comments
This is caused by a couple of aliases used in the current vite implementation (
/app
and/build
). If you rename your working directory you should be good to go, until https://github.com/nuxt/framework/pull/1180 is merged.Indeed, setting the
WORKDIR
inside the Dockerfile to another folder thanapp
works.