版本8升9编译报错Can't resolve all parameters for InMemoryStorageStrategy求助
问题解决方案:Angular 8升9后
InMemoryStorageStrategy依赖注入报错 Error: Can't resolve all parameters for InMemoryStorageStrategy: (?)
核心原因
该报错是Angular 9默认启用Ivy编译器后,第三方库的依赖注入元数据缺失导致的。InMemoryStorageStrategy通常来自@ngx-pwa/local-storage库,该库低于v9的版本不兼容Angular 9的编译规则。
可行解决步骤
- 第一步:升级
@ngx-pwa/local-storage到匹配Angular 9的版本
执行命令:npm install @ngx-pwa/local-storage@9
注意该库大版本需和Angular大版本一一对应,9.x的库版本适配Angular 9。 - 第二步:检查模块中的注入配置
如果你在AppModule或者CoreModule中手动配置过存储策略,需要删除旧的手动provide配置:
替换为导入官方预设模块:{ provide: StorageStrategy, useClass: InMemoryStorageStrategy }
先引入依赖:import { InMemoryStorageModule } from '@ngx-pwa/local-storage';
再在模块的imports数组中添加InMemoryStorageModule.forRoot()即可。 - 第三步:清理编译缓存重试
执行以下命令清除旧编译产物后重新启动服务:rm -rf node_modules/.cache && ng serve - 临时兼容方案:如果业务限制暂时不能升级第三方库,可以在
tsconfig.json的compilerOptions中添加配置,保留旧版DI元数据生成逻辑:"emitDecoratorMetadata": true,
同时可在angular.json中关闭Ivy作为过渡方案:"enableIvy": false
内容的提问来源于stack exchange,提问作者Prasanth
相关产品推荐
相关产品推荐

