Angular: tsconfig "composite":true flag not working with libraries within a ng-workspace

Discussão em 'Angular' iniciado por Itsyaboi, Novembro 5, 2024.

  1. Itsyaboi

    Itsyaboi Guest

    I've been trying to make this work, I have an NG16 workspace but whenever I use paths in my tsconfig.lib.json, the editor won't recognize the paths since it's not in the main tsconfig.json.

    However, I've tried to implement the new https://www.typescriptlang.org/docs/handbook/project-references.html reference feature to link my tsconfig.lib.ts to my root tsconfig.json but it seems to always fail and never recognize the files defined in the 'include' pattern.

    File 'drive/x/y/z/workspace/projects/my-lib/src/lib/my-lib.module.ts' is not listed within the file list of project 'drive/x/y/z/workspaceprojects/my-lib/tsconfig.lib.prod.json'. Projects must list all files or use an 'include' pattern.

    and

    Building entry point '@workspace/my-lib

    - Compiling with Angular sources in Ivy full compilation mode.
    × Compiling with Angular sources in Ivy full compilation mode.
    projects/my-lib/src/lib/test.service.ts:1:1 - error TS6307: File 'drive/x/y/z/workspace/projects/my-lib/src/lib/test.service.ngtypecheck.ts' is not listed within the file list of project 'drive/x/y/z/workspace/projects/my-lib/tsconfig.lib.json'. Projects must list all files or use an 'include' pattern.

    1

    projects/my-lib/src/public-api.ts:6:29 - error TS6307: File 'drive/x/y/z/workspace/projects/my-lib/src/lib/test.service.ts' is not listed within the file list of project 'drive/x/y/z/workspace/projects/my-lib/tsconfig.lib.json'. Projects must list all files or use an 'include' pattern.

    6 export { TestService } from './lib/test.service';
    `

    See tsconfig.lib.json below

    ./projects/my-lib/tsconfig.lib.json
    ```
    {
    "extends": "../../tsconfig.json",
    "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "declaration": true,
    "declarationMap": true,
    "inlineSources": true,
    "baseUrl": "./",
    "types": [],
    "paths": { /* classified */ },
    "composite": true,
    },
    "exclude": [
    "**/*.spec.ts",
    "**/*.test.ts",
    "**/*.stories.ts",
    "**/*.stories.js",
    "**/*.stories.ts",
    "**/*.stories.js"
    ],
    "include": [
    "src/**/*.ts",
    "src/**/*.d.ts"
    ]
    }
    ```

    Root tsconfig.json
    ```

    {
    "compileOnSave": false,
    "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,

    "lib": [
    "ES2022",
    "dom"
    ]
    },
    "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
    },
    }


    I'm expecting of course a compiling library on ng build my-lib but instead it's giving some strange errors which I'm unable to resolve. Does anyone know what's going on? I've provided all the patterns in the include property

    Continue reading...

Compartilhe esta Página