question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building a Nuxt 3 app inside Docker

See original GitHub issue

Environment

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

  1. create a new Nuxt 3 project: npx nuxi init .

  2. install this project dependencies yarn install

(at this stage it is working on the host machine without docker)

  1. 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" ]
  1. Create a .gitignore file containing:
.nuxt
.output
node_modules
Dockerfile
README.md
  1. start building the image docker build . -t nuxt-web:latest

  2. 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
danielroecommented, Oct 20, 2021

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.

0reactions
spacecowboy23commented, Oct 21, 2021

Indeed, setting the WORKDIR inside the Dockerfile to another folder than app works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a dockerized Nuxt 3 development environment
Now, cd nuxt-app or open the folder in your favorite IDE. Instead of installing the packages on our local machine, we want to...
Read more >
Get Started Running NuxtJS in a Docker Container
Docker NuxtJS tutorial. Dockerize NuxtJS app in 3 minutes. · Step 1 - Create a NuxtJS Project. Nuxt. · Setup Docker. Before creating...
Read more >
maciejpedzich/nuxt3-docker-template: Nuxt 3 x Pinia ... - GitHub
Nuxt 3 x Docker template ; Setup. Make sure to install the dependencies. npm install ; Development Server. Start the development server on...
Read more >
Deploy Nuxt on Koyeb Serverless Platform with Docker
Deploy the Nuxt application to production on Koyeb. On the Koyeb Control Panel, click the Create App button. In the form, fill the...
Read more >
Dockerize Nuxt.js
Inside the root of your app create a Dockerfile. This file is responsible for building and running your app on a designated port....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found