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

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

我想解决的问题

我在前端使用 docker-compose,在后端使用 Rails,当我尝试使用 Jest 测试 Nuxt 时,我发现我需要切换版本。所以我从 node:14.4.0-alpine 更改为 node:14.15.5-alpine 并尝试安装 Jest,但是在构建 node:14.15.5-alpine' 时出现 nuxt-i18n' 错误.我从 package.json 文件中删除了 'nuxt-i18n'。 node:14.15.5-alpine构建成功,Jest安装完成,但是下次使用docker-compose up命令时,报错。这种情况怎么办?

错误

✖ 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  |

代码

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

我以为是升级导致的故障,但这次错误是由nuxt.config.js中的i18n设置引起的。注释掉后,docker命令照常启动。

代码

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')
  //     }
  //   }
  // },