5

我创建了两个应用程序(第一个应用程序是一个库,另一个应用程序使用库中的组件)。

目的是延迟加载导入的库。

当我触发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.
  1. 该库是用以下内容构建的ng-packagr

    npm run cd
    
  2. 创建了一个库 *.tgz 文件。

    npm pack
    
  3. 在另一个应用程序中使用导入的库。

    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
                 ] 
                 }
4

0 回答 0