Как исправить ошибку ng build <lib> при переименовании public_api.ts в public-api.ts в обновлении angular8
Я нахожусь в процессе перехода от углового 7 к угловому 8 для библиотеки компонентов моей компании, созданной с помощью 'ng generate library'. Я старался быть как можно ближе к стандартной угловой конструкции. Я создал новое приложение и библиотеку с "@ angular / cli": "~ 8.2.0".
https://github.com/Annie-Huang/my-angular 8-app/tree/create-lib
Я заметил, что в angular 8 они изменяют public_api.ts на public-api.ts https://github.com/Annie-Huang/my-angular 8-app/blob/create-lib/projects/ea-ui/src/public-api.ts
Поэтому я переименовал файл записи из существующей библиотеки из public_api.ts в public-api.ts, а также обновил его в ng-package.json
И я получаю эту ошибку
Bradleys-MacBook-Pro:ea-component-library anniehuang$ ng build ea-ui
Building Angular Package
ERROR: error TS6053: File '/Users/anniehuang/projects/ea-component-library/projects/ea-ui/src/public_api.ts' not found.
An unhandled exception occurred: error TS6053: File '/Users/anniehuang/projects/ea-component-library/projects/ea-ui/src/public_api.ts' not found.
See "/private/var/folders/sw/1rxh903n6y39kkwbgr737n8m0000gp/T/ng-SE3jbI/angular-errors.log" for further details.
Когда я построил его в новом угловом приложении 8 в моем собственном репо (ng build ea-ui
). У меня нет этой ошибки.
И нет никакой строки public_api.ts, когда я выполнял глобальный поиск в библиотеке компонентов компании.
ng-package.json:
---------------------
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ea-ui",
"lib": {
"entryFile": "src/public-api.ts"
}
}
public-api.ts (file content not change, just renamed):
----------------------------------------------------------
export * from './lib/accordion/accordion.component';
export * from './lib/accordion/accordion.module';
export * from './lib/autocomplete/autocomplete-trigger.directive';
export * from './lib/autocomplete/autocomplete.component';
export * from './lib/autocomplete/autocomplete.module';
....
Bradleys-MacBook-Pro:ea-component-library anniehuang$ ng build ea-ui
Building Angular Package
ERROR: error TS6053: File '/Users/anniehuang/projects/ea-component-library/projects/ea-ui/src/public_api.ts' not found.
An unhandled exception occurred: error TS6053: File '/Users/anniehuang/projects/ea-component-library/projects/ea-ui/src/public_api.ts' not found.
See "/private/var/folders/sw/1rxh903n6y39kkwbgr737n8m0000gp/T/ng-SE3jbI/angular-errors.log" for further details.
Open up angular-errors.log:
------------------------------
Bradleys-MacBook-Pro:~ anniehuang$ cat /private/var/folders/sw/1rxh903n6y39kkwbgr737n8m0000gp/T/ng-MET38P/angular-errors.log
[error] Error: error TS6053: File '/Users/anniehuang/projects/ea-component-library/projects/ea-ui/src/public_api.ts' not found.
at analyseEntryPoint (/Users/anniehuang/projects/ea-component-library/node_modules/ng-packagr/lib/ng-v5/init/analyse-sources.transform.js:45:15)
at MapSubscriber.exports.analyseSourcesTransform.rxjs_1.pipe.operators_1.map.graph [as project] (/Users/anniehuang/projects/ea-component-library/node_modules/ng-packagr/lib/ng-v5/init/analyse-sources.transform.js:15:9)
at MapSubscriber._next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/operators/map.js:49:35)
at MapSubscriber.Subscriber.next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/Subscriber.js:66:18)
at SwitchMapSubscriber.notifyNext (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/operators/switchMap.js:86:26)
at InnerSubscriber._next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
at InnerSubscriber.Subscriber.next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/Subscriber.js:66:18)
at MapSubscriber._next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/operators/map.js:55:26)
at MapSubscriber.Subscriber.next (/Users/anniehuang/projects/ea-component-library/node_modules/rxjs/internal/Subscriber.js:66:18)
1 ответ
На самом деле выяснил причину. Оказалось, если ваша библиотека package.json
получил ngPackage
раздел, он будет принимать информацию там, а не в ng-package.json
, И если это ngPackage
раздел не имеет entryfile
, это займет src/public_api.ts
по умолчанию:
Итак, в ситуации FAILED содержимое моего файла: В /projects/ea-ui/package.json:
{
"name": "@ea/ea-ui",
"version": "1.13.5",
"peerDependencies": {
"@angular/common": "^8.2.0",
"@angular/core": "^8.2.0"
},
"dependencies": {
"dayjs": "^1.8.15",
"ngx-take-until-destroy": "^5.4.0",
"ngx-mask": "^8.0.2",
"@angular/cdk": "^8.1.2"
},
"ngPackage": {
"dest": "../../dist/ea-ui",
"whitelistedNonPeerDependencies": [
"dayjs",
"ngx-take-until-destroy",
"ngx-mask",
"@angular/cdk"
],
"lib": {
"styleIncludePaths": [
"./src/assets/scss"
]
}
}
}
В /projects/ea-ui/ng-package.json:
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ea-ui",
"lib": {
"entryFile": "src/public-api.ts"
}
}
Теперь я изменяю его на следующее, что оно ПРОЙДЕТ: В /projects/ea-ui/package.json:
{
"name": "@ea/ea-ui",
"version": "1.13.5",
"peerDependencies": {
"@angular/common": "^8.2.0",
"@angular/core": "^8.2.0"
},
"dependencies": {
"dayjs": "^1.8.15",
"ngx-take-until-destroy": "^5.4.0",
"ngx-mask": "^8.0.2",
"@angular/cdk": "^8.1.2"
}
}
В /projects/ea-ui/ng-package.json:
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ea-ui",
"lib": {
"styleIncludePaths": [
"./src/assets/scss"
],
"entryFile": "src/public-api.ts"
},
"whitelistedNonPeerDependencies": [
"dayjs",
"ngx-take-until-destroy",
"ngx-mask",
"@angular/cdk"
]
}