如何更新package.json以修复对等项依赖关系及其冲突?

时间:2019-08-19 21:09:46

标签: ionic-framework npm ionic3 package.json

我正在做一个相对较老的Ionic项目,该项目是由另一个在我公司之前工作过的人编写的,我无法正确构建它。原因是,当我运行npm install时,收到有关同级依赖项的过多警告。

我尝试手动安装对等依赖项,但没有成功。我发现这可能是由于依赖版本之间的某些冲突。但是我完全迷失了,因为我是Ionic和npm的新手。 我试图通过将对等依赖项添加到peerDependencies部分来更新我的package.json文件。现在是这样:

    "dependencies": {
        "@angular/common": "^6.0.0",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "^7.0.0",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "^6.0.0",
        "@angular/platform-browser-dynamic": "^6.0.0",
        "@ionic-native/camera": "^4.17.0",
        "@ionic-native/core": "^4.11.0",
        "@ionic-native/device": "^4.17.0",
        "@ionic-native/email-composer": "^4.17.0",
        "@ionic-native/firebase": "^4.15.0",
        "@ionic-native/keyboard": "^4.12.0",
        "@ionic-native/photo-viewer": "^4.17.0",
        "@ionic-native/social-sharing": "^4.16.0",
        "@ionic-native/splash-screen": "3.12.1",
        "@ionic-native/status-bar": "3.12.1",
        "@ionic/storage": "2.0.1",
        "@ngx-translate/core": "^11.0.0",
        "ajv": "^6.10.2",
        "angularfire2": "^5.0.2",
        "com-sarriaroman-photoviewer": "1.1.18",
        "cordova": "^9.0.0",
        "cordova-android": "^8.0.0",
        "cordova-ios": "^5.0.1",
        "cordova-plugin-androidx": "^1.0.2",
        "cordova-plugin-androidx-adapter": "^1.1.0",
        "cordova-plugin-camera": "4.0.3",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-email-composer": "0.8.15",
        "cordova-plugin-firebase": "^2.0.5",
        "cordova-plugin-firebasex": "^6.0.6",
        "cordova-plugin-ionic-keyboard": "^2.1.3",
        "cordova-plugin-ionic-webview": "^4.1.0",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-uniquedeviceid": "^1.3.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-plugin-x-socialsharing": "5.4.1",
        "es6-promise-plugin": "4.2.2",
        "firebase": "^5.5.3",
        "ionic-angular": "3.5.0",
        "ionicons": "3.0.0",
        "node-sass": "^4.9.3",
        "rxjs": "^6.3.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^3.2.4",
        "@ionic/cli-plugin-cordova": "1.4.1",
        "@ionic/cli-plugin-ionic-angular": "1.3.2",
        "install-peers": "^1.0.3",
        "typescript": "2.3.4"
    },
    "peerDependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "6.1.10",
        "@angular/core": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@firebase/app-types": "0.x",
        "@firebase/util": "0.x",
        "rxjs": "5.4.0",
        "zone.js": "~0.8.26"
    }

如您所见,有些依赖项在依赖项和peerDependencies部分上具有不同的版本。而且我不知道该怎么办。

我安装了一个名为install-peers的npm软件包,当我进行npm安装时,我得到了:

> install-peers@1.0.3 postinstall /Users/matheushr/workspace/Plis/plis-frontend/node_modules/install-peers
> node install.js

Installed peerDependencies as devDependencies via npm.
+ @angular/platform-browser-dynamic@4.1.3
+ @angular/platform-browser@4.1.3
+ rxjs@5.4.0
+ @angular/common@4.1.3
+ zone.js@0.8.29
+ @firebase/util@0.2.25
+ @angular/core@4.1.3
+ @angular/compiler@6.1.10
+ @firebase/app-types@0.4.3
added 7 packages from 2 contributors, updated 9 packages, moved 1 package and audited 9936 packages in 72.829s
found 0 vulnerabilities
npm WARN Plis@0.0.1 requires a peer of @angular/common@4.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of @angular/compiler@6.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of @angular/core@4.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of @angular/platform-browser@4.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of @angular/platform-browser-dynamic@4.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of rxjs@5.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN Plis@0.0.1 requires a peer of zone.js@~0.8.26 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/common@6.1.10 requires a peer of @angular/core@6.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler@4.1.3 requires a peer of @angular/core@4.1.3 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/core@7.2.15 requires a peer of zone.js@~0.8.26 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser@6.1.10 requires a peer of @angular/core@6.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@6.1.10 requires a peer of @angular/core@6.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/platform-browser-dynamic@6.1.10 requires a peer of @angular/compiler@6.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/core@4.20.0 requires a peer of rxjs@^5.5.11 but none is installed. You must install peer dependencies yourself.

尝试构建项目时,出现以下错误:

[17:15:01]  typescript: node_modules/@angular/compiler/src/output/output_ast.d.ts, line: 600 
            In 'const' enum declarations member initializer must be constant expression. 

     L599:      text?: string;
     L600:  } | {      
     L601:      tagName?: undefined;

[17:15:01]  typescript: node_modules/@angular/compiler/src/output/output_ast.d.ts, line: 601 
            In 'const' enum declarations member initializer must be constant expression. 

     L600:  } | {
     L601:      tagName?: undefined;
     L602:      text: string;

[17:15:01]  typescript: node_modules/@angular/compiler/src/output/output_ast.d.ts, line: 602 
            In 'const' enum declarations member initializer must be constant expression. 

     L601:      tagName?: undefined;
     L602:      text: string;      
     L603:  };

[17:15:01]  typescript: src/app/app.component.ts, line: 22 
            Cannot find module 'rxjs/operators'. 

      L21:  import { EditUser } from './../pages/edit/edit';
      L22:  import { tap } from 'rxjs/operators';
      L23:  import { PrivacidadePage } from '../pages/privacidade/privacidade';

[17:15:01]  typescript: src/app/app.component.ts, line: 86 
            Property 'disableScroll' does not exist on type 'Keyboard'. 

      L85:      this.rootPage = this.initComp();
      L86:      this.keyboard.disableScroll(true);
      L87:  });

[17:15:01]  typescript: src/components/authentication/authentication.ts, line: 26 
            Property 'disableScroll' does not exist on type 'Keyboard'. 

      L26:      this.keyboard.disableScroll(true);

[17:15:01]  typescript: src/pages/user-forgotpassword/user-forgotpassword.ts, line: 21 
            Property 'disableScroll' does not exist on type 'Keyboard'. 

      L21:    this.keyboard.disableScroll(false);

[17:15:01]  typescript: src/pages/user-signup/user-signup.ts, line: 32 
            Property 'disableScroll' does not exist on type 'Keyboard'. 

      L32:    this.keyboard.disableScroll(true);

我真的不知道如何使它工作。

1 个答案:

答案 0 :(得分:0)

我感到你很痛苦。我不使用Ionic,但会定期使用npm。每当您看到“您必须自己安装对等依赖项”时,通常这是一个很好的指示,您将需要执行此操作。

您已经知道如何使用npm安装软件包。请记住,在该命令中使用--save标志或--save-dev标志,以便在此过程中不断更新package.json文件。

我一直使用的效果很好的工具称为npm-check-updates,它帮助我极大地快速将旧的分期付款分解为更新的,可以使用的安装。

老实说,除非您在npm安装过程中不再遇到严重错误,否则我不会尝试再次构建。希望这会有所帮助!

[EDIT]:我意识到您可能正在问有关完全 peerDependencies的问题,这有点不同,而且我没有碰到太多。我确实找到了一篇似乎可以很好地解释它的文章:npm Peer Dependencies,希望这一点可以进一步阐明您的情况,并助您一臂之力!