You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 18升级Keycloak依赖版本后keycloak-angular无法找到keycloak-js的问题咨询

Angular 18升级Keycloak依赖版本后keycloak-angular无法找到keycloak-js的问题咨询

我们在Angular 18项目里准备把Keycloak从25版本升级到26版本,之前在package.json里用以下版本组合是完全正常运行的:

{
   ...
   "keycloak-angular": "^16.0.1",
   "keycloak-js": "^25.0.1",
   ...
}

现在我们尝试升级到Keycloak 26的版本,修改后的package.json依赖如下:

{
   ...
   "keycloak-angular": "^16.1.0",
   "keycloak-js": "^26.0.5",
   ...
}

但是现在执行构建的时候,出现了找不到模块'keycloak-js'或其对应的类型声明的错误。

我们的疑问是:为什么之前版本组合正常,升级后keycloak-angular就找不到keycloak-js了?

下面是我们项目的tsconfig.json配置:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "noImplicitOverride": true,
        "noPropertyAccessFromIndexSignature": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "esModuleInterop": true,
        "sourceMap": true,
        "declaration": false,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "importHelpers": true,
        "target": "ES2022",
        "module": "ES2022",
        "useDefineForClassFields": false,
        "lib": ["ES2022", "dom"],
        "paths": {
            "@core/*": ["./src/app/core/*"],
            "@shared/*": ["./src/app/shared/*"]
        },
        "resolveJsonModule": true, // Enable JSON imports (needed to import package.json in e.g. app/core/services/version.service.ts)
        "allowSyntheticDefaultImports": true // Allow default imports from modules with no default export (needed to import package.json in e.g. app/core/services/version.service.ts)
    },
    "angularCompilerOptions": {
        "enableI18nLegacyMessageIdFormat": false,
        "strictInjectionParameters": true,
        "strictInputAccessModifiers": true,
        "strictTemplates": true
    }
}

我尝试把moduleResolution从node改成bundler,结果又出现了另一个错误:找不到模块'@angular/core'。你的意思是要设置'allowSyntheticDefaultImports'为true吗?

如果把moduleResolution改回node,同时把keycloak-js降回25.0.1版本,一切又恢复正常了。有没有大佬能帮忙分析下原因?

备注:内容来源于stack exchange,提问作者jansolo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:18:04