5

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

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

我注意到在 Angular 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当我在自己的 repo ( )中的全新 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)

4

1 回答 1

8

真的找到了原因。事实证明,如果您的图书馆package.jsonngPackage部分,它将在那里获取信息,而不是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"
  ]
}
于 2019-08-15T04:32:27.420 回答