Home > Enterprise >  Nuxt not creating dist directory
Nuxt not creating dist directory

Time:10-18

I use docker-compose to build and run an SSR Nuxt.JS application. Web server is nginx.

I cannot use nginx reverse proxy to run this application, because directory dist is not created in /app/. This is my Dockerfile:

FROM node:14.17.0-alpine
WORKDIR /app
COPY . /app
RUN apk add python make g  
RUN yarn install
RUN yarn build
ENV HOST 0.0.0.0
ENV PORT 3000
ENV NODE_ENV production
EXPOSE 3000
CMD [ "yarn", "start" ]

It does not work. But If I run this command in my docker host path /home/path/project-1/ (the path Nuxt.JS files exist):

yarn start

I can temporarily see the application via:

http://ip:3000

I searched and tried some solutions, but none of them worked (unfortunately).

This is the log when I run yarn start in my terminal:

yarn run v1.22.11
$ nuxt start
ℹ [HPM] Proxy created: /api/  -> https://api.site.com/api
ℹ [HPM] Proxy rewrite rule created: "^/api/" ~> ""

   ╭───────────────────────────────────────────╮
   │                                           │
   │   Nuxt.js @ v2.14.3                       │
   │                                           │
   │   ▸ Environment: production               │
   │   ▸ Rendering:   server-side              │
   │   ▸ Target:      server                   │
   │                                           │
   │   Memory usage: 32.7 MB (RSS: 105 MB)     │
   │                                           │
   │   Listening: http://ip:3000/   │
   │                                           │
   ╰───────────────────────────────────────────╯

What is wrong for running?

The reason I cannot proxy pass it to nginx is that there's no document root. If I use # at the beginning of root directive, I use this error in nginx:

2021/10/14 12:02:29 [error] 25#25: *180 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET / HTTP/1.1", host: "app.site.com"
2021/10/14 12:02:29 [error] 25#25: *181 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET /favicon.ico HTTP/1.1", host: "app.site.com", referrer: "https://app.

Update 1

As said kissu, this is the related block in nuxt.config.js:

  target: 'server',
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0', // default: localhost
  },

CodePudding user response:

Using yarn build and targeting /app/.nuxt fixed the issue.

  • Related