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.

Build Nuxt 3 app in Docker using npm

See original GitHub issue

Environment

Host:

Nuxt CLI v3.0.0-27252861.4f9c87b RootDir: /projects/web/nuxt-test Nuxt project info:


  • Operating System: Linux
  • Node Version: v14.18.1
  • Nuxt Version: 3.0.0-27252861.4f9c87b
  • Package Manager: npm
  • Bundler: Vite
  • User Config: nitro
  • Runtime Modules: -
  • Build Modules: -

Inside the Docker building container:

Nuxt CLI v3.0.0-27252861.4f9c87b RootDir: /vue-build Nuxt project info:


  • Operating System: Linux
  • Node Version: v14.18.1
  • Nuxt Version: 3.0.0-27252861.4f9c87b
  • Package Manager: npm
  • Bundler: Vite
  • User Config: nitro
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

During the build of my Nuxt 3 app with npm inside the node:lts Docker image, the build fails saying sh: 1: nuxi: not found. When I do the same with Yarn as the package manager inside the node:lts Docker image, the build works fine and my application can be launched as a Docker container.

Reproduction

  1. Create a nuxt 3 project app: npx nuxi init nuxt3-app
  2. Install the dependencies: npm install
  3. Create a .dockignore file:
.nuxt
.output
node_modules
  1. Create a file Dockerfile containing the following content:
FROM node:lts as builder
WORKDIR /vue-bd
COPY package*.json ./
RUN npm install --prefer-offline --pure-lockfile --non-interactive --production=false
COPY . .
RUN npm run build

FROM node:lts-alpine
WORKDIR /app
COPY --from=builder /vue-bd/package*.json ./
RUN NODE_ENV=production npm install --pure-lockfile --non-interactive --production=true
COPY --from=builder /vue-bd/.output ./.output
EXPOSE 3000
ENTRYPOINT [ "npm", "run", "start" ]
  1. Build the image: docker build . -t=my-nuxt-image

Additional context

By replacing every occurrence of npm by its equivalent in Yarn, the Docker image builds perfectly. Also, by deleting package-lock.json, the build also completes.

Logs

Step 7/15 : RUN npm run build
 ---> Running in 1aa78248f392

> @ build /vue-bd
> nuxi build

sh: 1: nuxi: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @ build: `nuxi build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-10-25T16_21_08_211Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
toimccommented, Feb 18, 2022

@danielroe so sorry to disturb you.

Here my config, and it works.

FROM node:16 as builder
WORKDIR /vue-bd
COPY package*.json ./
RUN npm install --prefer-offline --pure-lockfile --non-interactive --production=false --registry=https://registry.npm.taobao.org
COPY . .
RUN npm run build

FROM node:lts-alpine
ENV NODE_ENV=production
ENV HOST 0.0.0.0 

WORKDIR /app
COPY --from=builder /vue-bd/package*.json ./
RUN NODE_ENV=production npm install --pure-lockfile --non-interactive --production=true --registry=https://registry.npm.taobao.org

COPY --from=builder /vue-bd/.output ./.output
EXPOSE 3000
ENTRYPOINT [ "npm", "run", "start" ]


0reactions
Guovincommented, May 1, 2022

I also meet this problem, nuxi not found, https://github.com/nuxt/framework/issues/4737

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deploy a NUXT.JS app via NPM and docker?
Open the Dockerfile with your preffered editor and paste the code below: FROM node:14.4.0-alpine3.12 AS BASE; # Create app directory ...
Read more >
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
This quickstart guide provides a basic introduction to the NuxtJS progressive framework running on docker. This is a great starting point if you...
Read more >
Deploying a Nuxt.js App with Docker - JonathanMH
Deploying a Nuxt.js App with Docker. Let's check out how you can deploy your Nuxt.js app, including server side rendering, with Docker.
Read more >
Dockerize Nuxt.js
Create a docker image of Nuxt.js app with Nginx proxy server and MySQL. ... Docker compose section. FROM node:12.16.3-alpine3.9 RUN mkdir -p ...
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