我购买了一个管理模板(来自wrappixel),它是一个 Angular 6 应用程序。我需要将其升级到 Angular 版本 7。我使用
完成此操作ng update --force --all
注意,我必须使用 --force 选项来确保更新完成,目的是在更新后修复对等依赖关系
现在需要修复以下对等依赖项,因为现在构建已损坏:
npm WARN ng2-smart-table@1.3.5 requires a peer of ng2-completer@^2.0.8 but none is installed. You must install peer dependencies yourself.
npm WARN ng2-smart-table@1.3.5 requires a peer of @angular/common@^6.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ng2-smart-table@1.3.5 requires a peer of @angular/core@^6.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ng2-smart-table@1.3.5 requires a peer of @angular/forms@^6.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-quill@4.5.0 requires a peer of quill@^1.3.6 but none is installed. You must install peer dependencies yourself.
在阅读了有关对等依赖项的各种文章(包括 Peer Dependencies ,其中讨论了很多有关插件的内容)后,我仍然不知道如何解释这些警告背后的含义或如何修复它们。
所以让我们看第一个:
ng2-smart-table@1.3.5 requires a peer of ng2-completer@^2.0.8
这是什么意思?
我的 package.json 包含(在依赖项部分):
"ng2-smart-table": "^1.3.5",
ng2-completer 不在我的 package.json 中,因为它不是直接依赖项。
这个错误是否来自于它当前未指定为直接依赖项而应该是的事实;即我应该只安装所需的版本,以便它是直接依赖项吗? (npm install ng2-completer@^2.0.8 ??)
我在其他文章中看到,有一个“peerDependency”可以进入package.json,这是我自己从未见过的。那么我应该创建此部分并向其添加“ng2-completer@^2.0.8”吗?
如果不修复这些对等依赖项,当我构建应用程序时,会收到以下错误:
λ ~/dev/github/js/wrappixel/admin-pro-angular-ng6-v2/admin-angular/ upgrade-framework* npm run start
> admin-angular@0.0.0 start /Users/Plastikfan/dev/github/js/wrappixel/admin-pro-angular-ng6-v2/admin-angular
> ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-01-22T13:20:28.970Z
Hash: c0785093f684bce10104
Time: 8859ms
chunk {main} main.js, main.js.map (main) 1.95 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 92.4 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 97.2 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 2.09 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 327 kB [initial] [rendered]
ERROR in multi ./src/styles.css ./node_modules/ngx-toastr/toastr.css ./node_modules/angular-calendar/css/angular-calendar.css ./node_modules/chartist/dist/chartist.css ./node_modules/quill/dist/quill.snow.css ./node_modules/dragula/dist/dragula.css ./src/assets/scss/style.scss
Module not found: Error: Can't resolve '/Users/Plastikfan/dev/github/js/wrappixel/admin-pro-angular-ng6-v2/admin-angular/node_modules/quill/dist/quill.snow.css' in '/Users/Plastikfan/dev/github/js/wrappixel/admin-pro-angular-ng6-v2/admin-angular'
ERROR in src/app/apps/apps.module.ts(7,31): error TS2307: Cannot find module 'ng2-dragula/ng2-dragula'.
src/app/apps/apps.module.ts(17,66): error TS2554: Expected 1-2 arguments, but got 0.
src/app/apps/fullcalendar/fullcalendar.component.ts(5,102): error TS2307: Cannot find module 'date-fns'.
src/app/charts/chartist-js/chartistjs.component.ts(3,39): error TS2307: Cannot find module 'ng-chartist/dist/chartist.component'.
src/app/charts/chartist-js/dynamic.component.ts(2,27): error TS2307: Cannot find module 'ng-chartist/dist/chartist.component'.
src/app/extra-component/drag-n-drop/drag.component.ts(11,25): error TS2339: Property 'subscribe' does not exist on type '(groupName?: string) => Observable<{ name: string; el: Element; source: Element; }>'.
src/app/extra-component/drag-n-drop/drag.component.ts(15,25): error TS2339: Property 'subscribe' does not exist on type '(groupName?: string) => Observable<{ name: string; el: Element; target: Element; source: Element; sibling: Element; }>'.
src/app/extra-component/drag-n-drop/drag.component.ts(19,25): error TS2339: Property 'subscribe' does not exist on type '(groupName?: string) => Observable<{ name: string; el: Element; container: Element; source: Element; }>'.
src/app/extra-component/drag-n-drop/drag.component.ts(23,24): error TS2339: Property 'subscribe' does not exist on type '(groupName?: string) => Observable<{ name: string; el: Element; container: Element; source: Element; }>'.
src/app/extra-component/drag-n-drop/drag.component.ts(27,30): error TS2339: Property 'subscribe' does not exist on type '<T = any>(groupName?: string) => Observable<{ name: string; el: Element; target: Element; source: Element; sibling: Element; item: T; sourceModel: T[]; targetModel: T[]; sourceIndex: number; targetIndex: number; }>'.
src/app/extra-component/drag-n-drop/drag.component.ts(30,32): error TS2339: Property 'subscribe' does not exist on type '<T = any>(groupName?: string) => Observable<{ name: string; el: Element; container: Element; source: Element; item: T; sourceModel: T[]; sourceIndex: number; }>'.
ℹ 「wdm」: Failed to compile.
多个 css 文件中存在多个错误、找不到模块错误和“类型上不存在属性‘订阅’”错误。我不知道它们是否与对等依赖项警告有关,但我猜它们是。
在我的 angular.json 中,我的“样式”部分包括:
"styles": [
"src/styles.css",
"node_modules/ngx-toastr/toastr.css",
"node_modules/angular-calendar/css/angular-calendar.css",
"node_modules/chartist/dist/chartist.css",
"node_modules/quill/dist/quill.snow.css",
"node_modules/dragula/dist/dragula.css",
"src/assets/scss/style.scss"
],
并且这些 css 文件与看到的“ERROR in multi”错误消息相匹配。我发现另一篇文章提到“src/styles.css”应该改为“styles.css”,我尝试了一下,但这没有什么区别。
另外:
ng2-smart-table@1.3.5 requires a peer of @angular/common@^6.0.1
ng2-smart-table@1.3.5 requires a peer of @angular/core@^6.0.1
ng2-smart-table@1.3.5 requires a peer of @angular/forms@^6.0.1
看起来 ng2-smart-table@1.3.5 依赖于 Angular 6,但我刚刚将项目升级到 Angular 7。那么“ng2-smart-table@1.3.5”是否有问题,并且依赖关系需要更改为与 Angular 7 兼容的更高版本?
我希望有人可以帮助我修复对等依赖警告,最终目标是修复所有这些构建错误。
谢谢。
最佳答案
如果您尚未安装此模块,请安装此模块。
npm i ng2-completer --save
并不是所有时候都需要这种依赖关系。我最近遇到了这个问题。在我的一个项目中,没有这个模块它也可以正常工作,但在第二个项目中我安装了它。然后就可以正常工作了。
对于其他 css 错误,看起来像是 css 问题。确保你以正确的方式获得了 css。否则,请尝试在样式数组中使用 ./node-modules...
。
最后一期。确保您的 package.josn
中具有此依赖项。
"dependencies": {
"@agm/core": "^1.0.0-beta.3",
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2"
....
}
关于node.js - 将 Angular 应用程序从版本 6 升级到版本 7 后如何修复对等依赖警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54311381/