我创建了两个应用程序(第一个应用程序是一个库,另一个应用程序正在从库中消耗组件)。
目的是延迟加载导入的库。
当我触发ng serve
时,它会给出错误消息,但是当我触发ng serve --prod --aot --build-optimizer
命令时没问题。 ng build
也会出现此问题。
Error:
ERROR in ./node_modules/bundle/bundle.d.ts
Module build failed: Error: D:\AngularApp\bundle\BaseApp\app2\node_modules\bundle\bundle.d.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format.
该库使用ng-packagr
:
npm run cd
创建了一个库* .tgz文件。
npm pack
使用另一个应用程序导入库。
npm install *.tgz
使用应用程序:tsconfig.json
//consuming application
{
// consuming application
"compileOnSave": false,
"compilerOptions": // consuming application {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
//consuming application
"lib": [
// test
"es2017",
"dom"
],
},
//consuming application
"include":[
//test
"src/**/*",
"node_modules/bundle",
],
// consuming application
"files": [
//consume application impored library
"node_modules/bundle/bundle.d.ts" // test
//consume application impored library
]
}