Nuxtjs和Docker:软件包文件已复制但仅部分安装?

问题描述 投票:0回答:1

我遇到了一个奇怪的错误。我有一个简单的dockerized nuxt项目:

mkdir my-project
cd my-project
npx create-nuxt-app frontend

这将导致项目回购具有以下结构:

my-project/
|-- frontend/
    |-- Dockerfile.development
    |-- assets/
    |-- ... (standard nuxt stuff)
|-- .env
|-- .dockerignore
docker-compose-development.yml

下面是docker-compose.development.yml和Dockerfile.development文件。我的软件包valph a中有一个依赖项,我将它放在Dockerfile中以确保我不会发疯(并且输出显示该软件包文件是正确的)。构建时,npm run install运行(不使用缓存)。但是,当我启动该服务时,出现一个错误,提示没有安装某些依赖项!我尝试过:

  • 修剪旧卷
  • 使用--no-cache选项进行构建
  • 删除.nuxtnode_modules目录并重建

以上各种组合

想法?

日志

docker-compose -f docker-compose.development.yml build

Building nuxt
Step 1/7 : FROM node:10.15
 ---> 5a401340b79f
Step 2/7 : ENV APP_ROOT /src
 ---> Using cache
 ---> f17aa506d708
Step 3/7 : RUN mkdir ${APP_ROOT}
 ---> Using cache
 ---> 9c553d4194eb
Step 4/7 : WORKDIR ${APP_ROOT}
 ---> Using cache
 ---> b35e54cee978
Step 5/7 : COPY ./frontend ${APP_ROOT}
 ---> 8e1c3daf89d7
Step 6/7 : RUN cat ${APP_ROOT}/package.json
{
  "dependencies: {
    ...,
    "valpha": "0.0.6"
  }
}
Step 7/7 : RUN npm install
 ---> Running in ...

docker-compose -f docker-compose.development.yml up

Attaching to nuxt_test
nuxt_1  | 
nuxt_1  | > [email protected] dev /src
nuxt_1  | > nuxt
nuxt_1  | 
nuxt_1  | ℹ Listening on: http://172.23.0.2:3000/
nuxt_1  | ℹ Preparing project for development
nuxt_1  | ℹ Initial build may take a while
nuxt_1  | ✔ Builder initialized
nuxt_1  | ✔ Nuxt files generated
nuxt_1  | ℹ Compiling Client
nuxt_1  | ✔ Client: Compiled with some errors in 27.09s
nuxt_1  | 
nuxt_1  |  ERROR  Failed to compile with 4 errors
nuxt_1  | 
nuxt_1  | These dependencies were not found:
nuxt_1  | 
nuxt_1  | * valpha in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/Table.vue?vue&type=script&lang=js&, ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./pages/table.vue?vue&type=script&lang=js& and 1 other

nuxt_1  | 
nuxt_1  | To install them, you can run: npm install --save valpha
nuxt_1  | ℹ Waiting for file changes
nuxt_1  | ℹ Memory usage: 429 MB (RSS: 590 MB)

文件

/frontend/Dockerfile.development

FROM node:10.15

ENV APP_ROOT /src

RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}

COPY ./frontend ${APP_ROOT}

RUN cat ${APP_ROOT}/package.json

RUN npm install

/docker-compose.development.yml

version: '3'

services:
  nuxt_test:
    image: frontend_test
    build:
      context: .
      dockerfile: ./frontend/Dockerfile.development
    restart: always
    ports:
      - "3000:3000"
    command: "npm run dev"
    environment:
      - HOST
    volumes:
      - ./frontend:/src

package.json

{
  "name": "frontend",
  "version": "1.0.0",
  "description": "test",
  "author": "me",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "test": "jest"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.3.6",
    "d3": "^5.14.1",
    "lodash": "^4.17.15",
    "nuxt": "^2.0.0",
    "plotly.js": "^1.51.1",
    "valpha": "0.0.6",
    "vue-scrollactive": "^0.8.0",
    "vuelidate": "^0.7.4"
  },
  "devDependencies": {
    "@nuxtjs/vuetify": "^1.0.0",
    "@vue/test-utils": "^1.0.0-beta.27",
    "babel-jest": "^24.1.0",
    "jest": "^24.1.0",
    "vue-jest": "^4.0.0-0"
  }
}

docker docker-compose nuxt.js
1个回答
0
投票

这个问题是出于懒惰而产生的!由于没有目录node_modules(因为OP指出要删除它),因此在安装时:

volumes:
  - ./frontend:/src

OP缺少原始node_modules会覆盖已安装的node_modules(在此示例中,因为npm installnode_modules下安装了/frontend

为了避免这种情况,请分别挂接每个与nuxt相关的子目录:

- ./frontend/assets:/src/assets
- ./frontend/components:/src/components
- ./frontend/layouts:/src/layouts
- ./frontend/pages:/src/pages
- ./frontend/plugins:/src/plugins
- ./frontend/static:/src/static
- ./frontend/store:/src/store
© www.soinside.com 2019 - 2024. All rights reserved.