构建我的Docker容器时GraphQL ERESOLVE无法解析依赖关系树 [英] GraphQL ERESOLVE unable to resolve dependency tree when building my docker container

查看:117
本文介绍了构建我的Docker容器时GraphQL ERESOLVE无法解析依赖关系树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的文件.

我认为这是问题的核心.

Here is I think the core of the problem.

Could not resolve dependency:
npm ERR! peer graphql@"^0.12.0 || ^0.13.0 || ^14.0.0" from graphql-middleware@4.0.2

docker-compose.yml

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

Dockerfile

# 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" ]

依赖性错误

$ 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

推荐答案

这里的问题当然是NPM和您要安装的软件包,而不是与Docker有关的任何事情.

The problem here is certainly with NPM and the packages you are trying to install rather than anything to do with Docker.

不幸的是,我无法重现您面临的确切错误.那可能是因为:

Unfortunately, I am not able to reproduce the exact error that you are facing. That could be because:

  • 从现在到发生此问题的时间发生了改变;
  • 您没有向我们展示一些重要的细节.

无论哪种方式,都有一种解决此类问题的通用方法,应该会有所帮助.但是首先要解释一下.

Either way, there's a general way in which such issues are solved, which should help. But first an explanation.

NPM的程序包(依赖项)管理机制允许程序包(依赖项)具有:

NPM's package (dependency) management mechanism allows packages (dependencies) to have:

  • (直接)依赖项-与软件包一起自动安装;
  • 对等依赖项-必须由软件包的使用者手动安装.
  • (direct) dependencies - installed automatically with the package;
  • peer dependencies - have to be manually installed by the consumer of the package.

但是,NPM 不允许不允许同一软件包的多个版本共存.

However, NPM does not allow multiple versions of the same package to coexist.

另外,您可能知道,程序包使用标准的语义版本控制,这意味着主要版本更改表示重大更改.

Also, as you may know, packages use standard semantic versioning, which means that a major version change indicates a breaking change.

由于这两个原因,如果一个程序包要求依赖项A为v1,而另一个程序包要求相同的依赖项A为v2,则会发生冲突.

Due to these two reasons, clashes occur if one package requires dependency A to be v1, while another wants the same dependency A to be v2.

NPM v7最近发布,这是当前(截至2020年11月) node:current 图像使用的版本.

NPM v7 was recently released and this is the version that current (as of November 2020) node:current images use.

NPM7带来的最大变化可能与对等方依赖性有关-NPM现在应该能够自动安装它们,如果可能.在此处了解详情.

Probably the biggest changes brought about by NPM7 relate to peer dependencies - NPM should now be able to install them automatically, if possible. Read more here.

如文档中所述,在无法解决冲突的情况下,NPM现在应该抛出错误而不是警告,这就是您所看到的.

As described in the document, in cases where it's not possible to solve the conflicts, NPM should now throw errors rather than warnings, which is what you are seeing.

我使用您的设置和NPM v7.0.8只能获得警告,没有错误,并且我不知道为什么.报告的问题本质上是相同的,因此解决方案应该非常相似.

I, on the other hand, only managed to get warnings and no errors using your setup and NPM v7.0.8, and I don't know why. The problems reported were essentially the same, however, so the resolution ought to be very similar.

我知道的唯一解决方案是手动解决冲突-开发人员需要调整其依赖关系才能发挥作用.

The only solution that I'm aware of is manual conflict resolution - the developer needs to adjust their dependencies to play along.

在您的特定情况下,问题似乎出在 graphql 包中.最新的 graphql 软件包是v15,这也是最新的 type-graphql 软件包(v1)的对等依赖项.

In your specific case the problem seems to be with the graphql package. The latest graphql package is v15, which is also a peer dependency of the latest type-graphql package (v1).

但是, apollo-server-express 具有一些依赖性,显然,它们仅支持 graphql 直至v14(包括v14).

However, apollo-server-express has a few dependencies, which apparently only support graphql up to and including v14.

在等待 apollo-server-express 完全支持v15时,可以通过降级唯一需要v15的软件包来完全选择 graphql v14.因此,如果您将 npm install 更改为此:

While you wait for apollo-server-express to fully support v15, you may opt for graphql v14 altogether by downgrading the only package that requires v15. So if you change your npm install to this:

npm install --save cors apollo-server-express express graphql@14 reflect-metadata type-graphql@0 apollo-datasource-rest soap jsonwebtoken

它应该工作...请注意,我们正在显式安装 graphql @ 14 type-graphql @ 0 (是,版本0).

it ought to work... Notice that we are explicitly installing graphql@14 and type-graphql@0 (yes, version zero).

也会给您一些不好的建议.在某些情况下,缺少对等项依赖关系可能不是问题,特别是如果您从不使用相关功能时.就您而言,这可能甚至没有什么问题,因为您确实具有依赖项,而不是必需的版本.错误版本完全可以解决问题.如果您感到幸运(或者您确定自己正在做的事情),并且确实希望继续使用 graphql v15,则可以:

Going to give you some bad advice too. In some cases a missing peer dependency may not be a problem, particularly if you never use the related functionality. In your case, it may be even less of a problem because you do have the dependency, just not the required version. It's entirely possible that a wrong version would do just fine. If you feel lucky (or if you're sure of you're doing) and you really wish to proceed with graphql v15, you could either:

  • 禁止任何NPM输出以使错误消失;
  • 降级到NPM v6,它的工作原理大不相同(尽管它仍然会警告您有关对等依赖的问题).

请谨慎操作

这篇关于构建我的Docker容器时GraphQL ERESOLVE无法解析依赖关系树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆