Beginner Professional
Beginner Professional

Reputation: 347

Error: Cannot find module 'nuxt-i18n' and docker-compose up does not start

What I want to solve

I'm using docker-compose with Nuxt front and Rails for the backend, and when I tried to use Jest for testing Nuxt, I found that I needed to switch versions. So I changed from node:14.4.0-alpine to node:14.15.5-alpine and tried to install Jest, but I got a nuxt-i18n' error when building node:14.15.5-alpine'. I removed 'nuxt-i18n' from the package.json file. The build of node:14.15.5-alpine was successful and the installation of Jest was completed, but the next time I used the docker-compose up command, I got an error. What should I do in this case?

Error

✖ Nuxt Fatal Error

front_1  |
front_1  |    ╭─────────────────────────────────────────────────╮
front_1  |    │                                                 │
front_1  |    │   ✖ Nuxt Fatal Error                            │
front_1  |    │                                                 │
front_1  |    │   Error: Cannot find module 'nuxt-i18n'         │
front_1  |    │   Require stack:                                │
front_1  |    │   - /app/node_modules/@nuxt/core/dist/core.js   │
front_1  |    │                                                 │
front_1  |    ╰─────────────────────────────────────────────────╯
front_1  |

Code

package.json

{
  "name": "app",
  "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": "yarn lint:js"
  },
  "dependencies": {
    "@nuxtjs/auth": "^4.9.1",
    "@nuxtjs/axios": "^5.13.1",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^27.4.6",
    "core-js": "^3.9.1",
    "jest": "^27.4.7",
    "nuxt": "^2.15.3",
    "vue-jest": "^3.0.7"
  },
  "devDependencies": {
    "@nuxtjs/eslint-config": "^6.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/vuetify": "^1.11.3",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.22.0",
    "eslint-plugin-nuxt": "^2.0.0",
    "eslint-plugin-vue": "^7.7.0"
  }
}

Dockerfile

FROM node:14.15.5-alpine

ARG WORKDIR
ARG CONTAINER_PORT
ARG API_URL

ENV HOME=/${WORKDIR} \
    LANG=C.UTF-8 \
    TZ=Asia/Tokyo \
    HOST=0.0.0.0 \
    API_URL=${API_URL} \
    NPM_CONFIG_PRODUCTION=false

# ENV確認
RUN echo ${HOME}
RUN echo ${CONTAINER_PORT}
RUN echo ${API_URL}

WORKDIR ${HOME}

COPY package*.json ./

#Vutify導入
RUN apk update && \
    apk upgrade && \
    apk add --no-cache make gcc g++ python && \
    yarn install

COPY . .

RUN yarn run build

EXPOSE ${CONTAINER_PORT}

docker-compose.yml

version: '3.8'

services:
  db:
    image: postgres:12.3-alpine
    environment:
      TZ: UTC
      PGTZ: UTC
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
    volumes:
      - ./api/tmp/db:/var/lib/postgresql/data

  api:
    build:
      context: ./api
      args:
        WORKDIR: $WORKDIR
    command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    environment:
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
      API_DOMAIN: "localhost:$FRONT_PORT"
    volumes:
      - ./api:/$WORKDIR
    depends_on:
      - db
    ports:
      - "$API_PORT:$CONTAINER_PORT"

  front:
    build:
      context: ./front
      args:
        WORKDIR: $WORKDIR
        CONTAINER_PORT: $CONTAINER_PORT
        API_URL: "http://localhost:$API_PORT"
    command: yarn run dev
    volumes:
      - ./front:/$WORKDIR
    ports:
      - "$FRONT_PORT:$CONTAINER_PORT"
    depends_on:
      - api

Upvotes: 1

Views: 2307

Answers (1)

Beginner Professional
Beginner Professional

Reputation: 347

I thought it was a glitch that had been caused by the upgrade, but this time the error was caused by the i18n settings in nuxt.config.js. After commenting it out, the docker command started as usual.

Code

nuxt.config.js


  // Doc: https://nuxt-community.github.io/nuxt-i18n/basic-usage.html#nuxt-link
  // i18n: {
  //   locales: ['ja', 'en'],
  //   defaultLocale: 'ja',
  //   vueI18n: {
  //     fallbackLocale: 'ja',
  //     silentFallbackWarn: true,
  //     messages: {
  //       ja: require('./locales/ja.json'),
  //       en: require('./locales/en.json')
  //     }
  //   }
  // },

Upvotes: 1

Related Questions