Christian Giupponi
Christian Giupponi

Reputation: 7618

Local env with Docker for nuxtjs

I'm trying to create a local env with docker for a nuxtjs project.
This is my docker-compose.yml:

version: '3.3'

services:
  frontend:
    container_name: frontend
    restart: unless-stopped
    working_dir: /app
    build:
      dockerfile: Dockerfile
    volumes:
      - ./application:/app
    ports:
      - "3001:3000"
    environment:
      HOST: 0.0.0.0
    command: npm run dev

This is my Dockerfile

FROM alpine:3.15

RUN apk update
RUN apk add --no-cache --update make
RUN apk add --no-cache --update python3 py3-pip
RUN apk add --no-cache --update nodejs npm
RUN apk add --no-cache --update g++

WORKDIR /app

COPY application /app

RUN npm install -g nuxt
RUN NODE_ENV=development npm install
RUN npm install

ENV HOST 0.0.0.0

EXPOSE 3001

When I run docker-compose up --build

✖ Nuxt Fatal Error Error: Cannot find module '@nuxtjs/eslint-module'
Require stack:

  • /usr/local/lib/node_modules/nuxt/node_modules/@nuxt/core/dist/core.js

This is my package.json

{
  "name": "demo",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
    "lint": "npm run lint:js",
    "lintfix": "npm run lint:js -- --fix",
    "lintreport": "npm run lint:js -- -f node_modules/eslint-html-reporter/reporter.js -o eslint-report.html",
    "test": "jest"
  },
  "dependencies": {
    "@nuxtjs/auth-next": "5.0.0-1637745161.ea53f98",
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/sitemap": "^2.4.0",
    "axios": "^0.24.0",
    "core-js": "^3.19.3",
    "nuxt": "^2.15.8",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    "@babel/eslint-parser": "^7.16.3",
    "@nuxt/test-utils": "^0.2.2",
    "@nuxtjs/eslint-config": "^8.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/google-fonts": "^1.3.0",
    "@nuxtjs/tailwindcss": "^4.2.1",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^27.4.4",
    "eslint": "^8.4.1",
    "eslint-html-reporter": "^0.7.4",
    "eslint-plugin-nuxt": "^3.1.0",
    "eslint-plugin-vue": "^8.2.0",
    "express": "^4.17.2",
    "jest": "^27.4.5",
    "postcss": "^8.4.4",
    "supertest": "^6.1.6",
    "vue-jest": "^3.0.4"
  }
}

Looks like that the devDependencies are not installed.
Any idea how to run the prject?

Upvotes: 2

Views: 897

Answers (1)

TJ H.
TJ H.

Reputation: 294

You can use this hack to avoid mounting your node_modules and overriding the ones in the container.

volumes:
      - ./application:/app
      - /app/node_modules

ref: Docker-compose: node_modules not present in a volume after npm install succeeds

Upvotes: 1

Related Questions