我正在尝试开发一个使用某些 3rd 方依赖项的库。我跟着https://angular.io/guide/creating-libraries。
这是结构:
dist
|-corp
|-angular-core
node_modules
projects
|-corp
|-angular-core
| package.json
| tsconfig.lib.json
angular.json
package.json
tsconfig.json
这是库主 package.json
{
"name": "node-libraries",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.1.2",
"@angular/common": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/core": "~8.1.2",
"@angular/forms": "~8.1.2",
"@angular/platform-browser": "~8.1.2",
"@angular/platform-browser-dynamic": "~8.1.2",
"@angular/router": "~8.1.2",
"@ionic-native/core": "^5.20.0",
"@ionic-native/device": "^5.20.0",
"@ionic-native/facebook": "^5.20.0",
"@ionic-native/in-app-browser": "^5.20.0",
"@ionic/angular": "^4.11.10",
"@ionic/storage": "^2.2.0",
"@ngx-translate/core": "^11.0.1",
"rxjs": "~6.4.0",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.23",
"@angular-devkit/build-ng-packagr": "~0.801.3",
"@angular/cli": "~8.1.2",
"@angular/compiler-cli": "~8.1.2",
"@angular/language-service": "~8.1.2",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ng-packagr": "^5.1.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tsickle": "^0.35.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
}
}
这里的图书馆项目/corp/angular-corepackage.json
{
"name": "@corp/angular-core",
"version": "0.3.0",
"author": "",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": false,
"peerDependencies": {
"@angular/animations": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/platform-browser": "~8.1.2",
"@angular/platform-browser-dynamic": "~8.1.2",
"@angular-devkit/build-angular": "^0.803.23",
"@angular-devkit/build-ng-packagr": "~0.801.3",
"@angular/cli": "~8.1.2",
"@angular/common": "^8.2.14",
"@angular/compiler-cli": "~8.1.2",
"@angular/core": "^8.2.14",
"@angular/forms": "^8.2.14",
"@angular/language-service": "~8.1.2",
"@angular/router": "^8.2.14",
"@ionic-native/core": "^5.20.0",
"@ionic-native/device": "^5.20.0",
"@ionic-native/facebook": "^5.20.0",
"@ionic-native/in-app-browser": "^5.20.0",
"@ionic/angular": "^4.11.10",
"@ionic/storage": "^2.2.0",
"@ngx-translate/core": "^11.0.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ng-packagr": "^5.1.0",
"protractor": "~5.4.0",
"rxjs": "^6.5.4",
"ts-node": "~7.0.0",
"tsickle": "^0.35.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
}
}
我构建了库并通过符号链接到主项目npm link
,但是当我尝试运行它时,我在控制台中遇到了这些错误:
ERROR in node_modules/@next-adv/angular-core/lib/ionic-components/sign-up/sign-up.component.d.ts:5:30 - error TS2307: Cannot find module '@ionic-native/in-app-browser/ngx'.
[ng] 5 import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
[ng] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng] node_modules/@next-adv/angular-core/lib/services/authentication/auth.apple.d.ts:3:25 - error TS2307: Cannot find module '@ionic/storage'.
[ng] 3 import { Storage } from '@ionic/storage';
[ng] ~~~~~~~~~~~~~~~~
[ng] node_modules/@next-adv/angular-core/lib/services/authentication/auth.facebook.d.ts:3:26 - error TS2307: Cannot find module '@ionic-native/facebook/ngx'.
[ng] 3 import { Facebook } from '@ionic-native/facebook/ngx';
[ng] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng] node_modules/@next-adv/angular-core/lib/services/authentication/auth.facebook.d.ts:4:25 - error TS2307: Cannot find module '@ionic/storage'.
[ng] 4 import { Storage } from '@ionic/storage';
[ng] ~~~~~~~~~~~~~~~~
[ng] node_modules/@next-adv/angular-core/lib/services/authentication/auth.plain.d.ts:3:25 - error TS2307: Cannot find module '@ionic/storage'.
[ng] 3 import { Storage } from '@ionic/storage';
[ng] ~~~~~~~~~~~~~~~~
[ng] node_modules/@next-adv/angular-core/lib/services/authentication/auth.wordpress.d.ts:3:25 - error TS2307: Cannot find module '@ionic/storage'.
[ng] 3 import { Storage } from '@ionic/storage';
[ng]
~~~~~~~~~~~~~~~~
似乎编译器正在主项目中寻找库依赖项node_modules
,证明只有@ionic
不在主项目中的部门给了我错误。
我也在tsconfig.lib.json
库angular-core
文件夹中尝试了这个:
"paths": {
"@ionic/storage": [
"node_modules/@ionic/storage"
]
}
在主项目中angular.json
"preserveSymLinks": true
但它没有用。
我认为问题在于该库是通过符号链接而不是常规的npm i
. 所以我的问题是:我该如何管理 peerDependencies?我必须在主要项目中手动安装它们吗?