【问题标题】:Angular. Dependency conflict when trying to install ngx-cookie角。尝试安装 ngx-cookie 时的依赖冲突
【发布时间】:2022-01-02 22:01:08
【问题描述】:

我正在尝试安装 ngx-cookie 包,以便可以在我的应用程序中使用 CookieService。但是,我得到以下依赖冲突:

$ npm install ngx-cookie --save
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: angular-frontend@0.0.0
npm ERR! Found: @angular/core@13.0.3
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~13.0.0" from the root project
npm ERR!   peer @angular/core@">9.0.0" from ngx-cookie@5.0.2
npm ERR!   node_modules/ngx-cookie
npm ERR!     ngx-cookie@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"13.1.1" from @angular/common@13.1.1
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@">9.0.0" from ngx-cookie@5.0.2
npm ERR!   node_modules/ngx-cookie
npm ERR!     ngx-cookie@"*" 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.

我尝试安装ngx-cookie-service,但我得到了同样的错误。

我该怎么办?是不是 Angular 版本的问题?

【问题讨论】:

    标签: angular typescript npm cookies dependencies


    【解决方案1】:

    这不是角度问题。它更多地与 npm7 版本有关。

    在之前版本的npm(4-6)中,peer依赖冲突 提出版本不兼容的警告,但仍会 安装依赖项没有错误。 npm 7 将阻止安装 如果存在无法解决的上游依赖冲突 自动解决。

    理想情况下,您不应该像在 ngx-cookie 包中那样收到此错误,angular peer deps 定义为 > 这意味着它将与大于 9 的所有 angular 版本兼容。

    根据错误日志中的建议,您可以使用 --force 标志或 --legacy-peer-deps(此行为类似于版本 4-6)。

    参考:-https://github.blog/2021-02-02-npm-7-is-now-generally-available/

    【讨论】:

    • 谢谢你^_^ @Vimal Patel
    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 2023-01-03
    相关资源
    最近更新 更多