延迟加载:TypeScript编译中缺少。请通过“'文件”确保它在您的tsconfig中。或者包括'属性

时间:2018-04-02 03:56:52

标签: angular lazy-loading ng-packagr

我创建了两个应用程序(第一个应用程序是一个库,另一个应用程序正在从库中消耗组件)。

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

当我触发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
    
  4. 使用应用程序: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
                     ] 
                     }
    

0 个答案:

没有答案