在angular8升级中将public_api.ts重命名为public-api.ts时,如何修复ng build <lib>错误

时间:2019-08-15 01:39:59

标签: angular8 angular-library angular-cli-v8

我正在将使用“ ng generate library”构建的公司组件库的angular 7迁移到angular 8。我试图尽可能接近标准的角度cli构建。我创建了一个全新的应用程序和一个带有“ @ angular / cli”的库:“〜8.2.0”。

https://github.com/Annie-Huang/my-angular8-app/tree/create-lib

我注意到在角度8中,它们将public_api.ts更改为public-api.ts https://github.com/Annie-Huang/my-angular8-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.

当我在自己的仓库(ng build ea-ui)中用全新的angular 8应用程序构建它时。我没有这个错误。

当我在公司组件库上进行全局搜索时,没有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 个答案:

答案 0 :(得分:1)

实际上找到了原因。原来,如果您的图书馆的package.json拥有ngPackage部分,它将在此处获取信息,而不是ng-package.json中的信息。并且如果该ngPackage部分没有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"
  },
  "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"
  ]
}