Angular 9 CLI ignores custom .d.ts files

Discussão em 'Angular' iniciado por Walnussbär, Março 21, 2025.

  1. Walnussbär

    Walnussbär Guest

    I have to maintain an old Angular 9 App. I cannot upgrade to Angular 10 or higher.

    Consider the following import:

    import Keycloak, { KeycloakProfile } from "keycloak-js";


    The typescript compiler recognizes that import without any errors, because this is my respective type augmentation file under src/typing/keycloak-js.d.ts. VsCode even allows my to go to the respective typings, so the TS compiler recognized my custom .d.ts file.

    declare module "keycloak-js" {
    import Keycloak from "keycloak-js/lib/keycloak";
    export default Keycloak;
    export * from "keycloak-js/lib/keycloak";
    }


    In my package.json:

    "dependencies": {
    "keycloak-js": "^26.1.4",
    }


    This is my tsconfig.json:

    {
    "compileOnSave": false,
    "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "resolveJsonModule": true,
    "typeRoots": ["node_modules/@types", "./src/typing"],
    "lib": ["es2017", "esnext.array", "dom"],
    "paths": {
    "@app/*": ["./src/app/*"],
    "@environment/*": ["./src/environments/*"],
    "keycloak-js": ["./src/typing/keycloak-js"]
    }
    },
    "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableIvy": false
    }
    }


    And this is my tsconfig.app.json:

    {
    "extends": "./tsconfig.json",
    "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
    },
    "files": ["src/main.ts", "src/polyfills.ts"],
    "include": ["src/**/*.ts", "src/typing/*.d.ts"],
    "exclude": ["src/test.ts", "src/**/*.spec.ts"]
    }


    But the Angular CLI notes the following error when starting my Angular 9 app via ng serve:

    ERROR in ./src/app/utils/auth/keycloak.service.ts
    Module not found: Error: Can't resolve 'keycloak-js' in 'C:\Development\02_Artefakte\manual-data-collection\angular\src\app\utils\auth'


    Can someone help me?

    Continue reading...

Compartilhe esta Página