使用ng-packagr构建Secondary Entry Points时遇TS6053错误求助
Building entry point 'ngx'
✔ Compiling with Angular sources in Ivy partial compilation mode.
✔ Writing FESM bundles
✔ Copying assets
✔ Writing package manifest
✔ Built ngx
Building entry point 'ngx/src/animations'
✖ Compiling with Angular sources in Ivy partial compilation mode.
error TS6053: File '/Projects/ngx/src/animations/src/public_api.ngtypecheck.ts' not found.
The file is in the program because:
Root file specified for compilation
error TS6053: File '/Projects/ngx/src/animations/src/public_api.ts' not found.
The file is in the program because:
Root file specified for compilation
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! base-angular@0.0.1 build-ngx: ng build ngx --configuration production
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the base-angular@0.0.1 build-ngx script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/truongtran/.npm/_logs/2022-12-02T09_56_16_832Z-debug.log
# 排查与解决步骤 ## 1. 修正次级入口目录结构 报错显示ng-packagr在`src/animations`下额外查找`src`子目录,说明次级入口结构不符合预期。正确结构应为:
ngx/
src/
animations/
public_api.ts // 直接放在animations目录下
package.json
lib/
...
public_api.ts
package.json
移除`src/animations`下多余的嵌套`src`文件夹,将`public_api.ts`直接置于次级入口根目录。 ## 2. 检查次级入口package.json配置 打开`src/animations/package.json`,确保`entryFile`路径正确指向当前目录下的入口文件: ```json { "ngPackage": { "entryFile": "public_api.ts" }, "name": "ngx/src/animations" }
避免写成src/public_api.ts(除非确实存在嵌套结构)。
3. 调整tsconfig文件规则
根目录tsconfig.json需确保包含次级入口的所有文件:
"include": [ "src/**/*.ts", "src/animations/**/*.ts" ], "exclude": [ "node_modules", "dist" ]
如果次级入口有单独的tsconfig.animations.json,也要保证其include规则覆盖自身目录的文件。
4. 清理构建缓存
执行命令清理缓存,避免旧构建残留干扰:
rm -rf node_modules/.cache ng build ngx --configuration production --clean
5. 验证版本兼容性
确保ng-packagr版本与Angular CLI版本匹配(Angular 14+建议使用ng-packagr 14+版本),可执行以下命令升级:
npm install ng-packagr@latest --save-dev
内容的提问来源于stack exchange,提问作者Travis Tran

