zab*_*mba 8 docker dockerfile docker-compose graphql
这是我的文件。
这里是我认为问题的核心。
Could not resolve dependency:
npm ERR! peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from graphql-middleware@4.0.2
Run Code Online (Sandbox Code Playgroud)
version: '3.7'
services:
apollo:
container_name: apollo
build:
context: .
dockerfile: Dockerfile
environment:
- NODE_ENV=development
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- 4000:4000
restart: always
Run Code Online (Sandbox Code Playgroud)
# Use the official image as a parent image.
FROM node:current-slim
# Set the working directory.
WORKDIR /app
# Setting environment path.
ENV PATH=/app/node_modules/.bin:$PATH
# Copy the file from your host to your current location.
COPY package.json .
# Run the command inside your image filesystem.
RUN npm init --yes
RUN npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes
RUN npm install nodemon -g --yes
# Add metadata to the image to describe which port the container is listening on at runtime.
EXPOSE 4000
# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .
CMD [ "nodemon", "index.js" ]
Run Code Online (Sandbox Code Playgroud)
$ docker-compose up --build
Building apollo
Step 1/10 : FROM node:current-slim
---> f3f62dfcc735
Step 2/10 : WORKDIR /app
---> Using cache
---> 33088e65c748
Step 3/10 : ENV PATH=/app/node_modules/.bin:$PATH
---> Using cache
---> c7f742267b26
Step 4/10 : COPY package.json .
---> Using cache
---> 76285ea4a8ca
Step 5/10 : RUN npm init --yes
---> Using cache
---> 29a3d715136b
Step 6/10 : RUN npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes
---> Running in 1e4472bcd901
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: apollo-express-server@1.0.0
npm ERR! Found: graphql@15.4.0
npm ERR! node_modules/graphql
npm ERR! graphql@"^15.3.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from graphql-middleware@4.0.2
npm ERR! node_modules/graphql-middleware
npm ERR! graphql-middleware@"^4.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-05T16_19_42_605Z-debug.log
ERROR: Service 'apollo' failed to build : The command '/bin/sh -c npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
小智 9
不需要降级到 npm 6。 事实上,npm 7 仍然可以与选项 --legacy-peer-deps 一起使用。
npm install --legacy-peer-deps
Run Code Online (Sandbox Code Playgroud)
这里的问题肯定与 NPM 和您尝试安装的包有关,而不是与 Docker 有任何关系。
不幸的是,我无法重现您所面临的确切错误。那可能是因为:
无论哪种方式,都有解决此类问题的一般方法,这应该会有所帮助。但首先是一个解释。
NPM 的包(依赖)管理机制允许包(依赖)具有:
然而,NPM也不会允许同一个包的多个版本共存。
此外,您可能知道,包使用标准语义版本控制,这意味着主要版本更改表示重大更改。
由于这两个原因,如果一个包需要依赖项 A 为 v1,而另一个包希望相同的依赖项 A 为 v2,则会发生冲突。
NPM v7 最近发布,这是当前(截至 2020 年 11 月)node:current图像使用的版本。
NPM7 带来的最大变化可能与对等依赖项有关 -如果可能,NPM 现在应该能够自动安装它们。在这里阅读更多。
如文档中所述,在无法解决冲突的情况下,NPM 现在应该抛出错误而不是警告,这就是您所看到的。
另一方面,我使用您的设置和 NPM v7.0.8 仅设法收到警告而没有错误,我不知道为什么。但是,报告的问题基本上相同,因此解决方案应该非常相似。
我知道的唯一解决方案是手动解决冲突 - 开发人员需要调整他们的依赖项以配合使用。
在您的特定情况下,问题似乎出在graphql包上。最新graphql包是v15,也是最新type-graphql包(v1)的peer依赖。
但是,apollo-server-express有一些依赖项,显然只支持graphqlv14 及以下版本。
在您等待apollo-server-express完全支持 v15 时,您可以graphql通过降级唯一需要 v15 的软件包来完全选择v14。所以如果你改变你的npm install:
npm install --save cors apollo-server-express express graphql@14 reflect-metadata type-graphql@0 apollo-datasource-rest soap jsonwebtoken
Run Code Online (Sandbox Code Playgroud)
它应该可以工作...请注意,我们正在明确安装graphql@14和type-graphql@0(是的,版本零)。
也会给你一些不好的建议。在某些情况下,缺少对等依赖可能不是问题,特别是如果您从不使用相关功能。在您的情况下,它可能更不成问题,因为您确实有依赖关系,而不是所需的版本。完全有可能错误的版本会做得很好。如果您感到幸运(或者您确定自己在做)并且您真的希望继续使用graphqlv15,您可以:
谨慎行事!