我遇到了一个奇怪的错误。我有一个简单的文档化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下面是dockerCompose.Development.yml和Dockerfile.development文件。我的包valpha中有一个依赖项,我在Dockerfile中进行了猫操作,以确保我不会发疯(输出结果显示包文件是正确的)。当我构建时,npm run install运行(不使用缓存)。然而,当我旋转这个服务时,我会发现一个错误,就是没有安装一些依赖项!我试过:
用volumes
.nuxt、node_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 | > frontend@1.0.0 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:/srcpackage.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"
}
}发布于 2019-11-19 13:17:27
问题在于它是从懒惰中发展出来的!由于没有目录node_modules ( OP状态是删除它),所以在挂载时:
volumes:
- ./frontend:/srcOP缺少原始node_modules覆盖了安装的node_modules (在本例中,npm install在/frontend下安装node_modules )
为了避免这种情况,分别挂载每个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/storehttps://stackoverflow.com/questions/58934887
复制相似问题