3
$ npm run start

> app@1.2.3 start /home/app/ui/web
> nuxt start

FATAL  No build files found in /home/app/ui/web/.nuxt/dist/server.
Use either `nuxt build` or `builder.build()` or start nuxt in development mode.

Error happens when starting a Nuxt.js app in a Docker image that was built multi-stage:

  1. npm ci && npm run build inside the build-stage image
  2. copy the built app .nuxt, and also package.json and node_modules into the run-stage image

Some details regarding the environment.

Nuxt.js application mode is 'spa'. The missing files are really present inside the final image, no volumes/mounts have been used. OS user names are different between build-stage and run-stage images, however (hopefully) that should not be the case.

Nuxt.js 2.12.2, Node.js 14.16.0.

  • 2
    Can you provide a [mcve], including your `Dockerfile` and how you're starting the container? In particular, are you overwriting the image's code with volumes or bind mounts? – David Maze Apr 07 '21 at 13:38
  • @DavidMaze thank you for your swift answer, I've found the root cause and updated the question with the environment details. Many thanks! – Sand Pipersburg Apr 07 '21 at 15:29

1 Answers1

2

The nuxt.config.js was missing.

After I've copied it into the run-stage image, and switched from localhost to a 0.0.0.0 for server.host property inside the nuxt.config.js, container is running fine:

> app@1.2.3 start /home/app/ui/web
> nuxt start

ℹ Listening on: http://172.17.0.2:3000/

Thus the required items for running a prod build in a server deployment mode are (seemingly) following:

/.nuxt
/node_modules
nuxt.config.js
package.json

The documentation is somehow vague regarding what should be included into the final artifact: https://nuxtjs.org/docs/2.x/get-started/commands/#server-deployment

A different SO question that inspired the troubleshooting: Nuxt deployment error: server resources are not available

Update

Updated Nuxt to 2.15.3, switched from ad-hoc npm build to a reproducible build via yarn.

The build stage have become a yarn install --frozen-lockfile && yarn build. Also, copying node_modules from build stage into run stage brings development dependencies into prod, b/c prod build of Nuxt app requires development dependencies. Thus during a run stage, switched to a yarn install --frozen-lockfile --production=true instead of copying node_modules from a previous build stage.

The required items copied from a build stage for running a prod Nuxt app in a server deployment mode (https://nuxtjs.org/docs/2.x/features/deployment-targets/#server-hosting) are thus following:

/.nuxt
nuxt.config.js
package.json
yarn.lock