NestJS + Angular 项目抛出未找到模块:错误:无法解析“缓存管理器"管理器、缓存、抛出、未找到

2023-09-07 14:39:23 作者:姐√就是这么拽℉

我有一个 NestJS 后端 (6.9.0) 和 Angular 前端项目 (8.2.11).我在本地主机中同时使用并行启动前端和后端.

I have a NestJS backend (6.9.0) and Angular frontend project (8.2.11). I use concurrently to start the front end and backend in parallel in my localhost.

后端启动正常(启动速度更快),但是当 Angular 项目开始编译并准备好编译时,它会抛出以下错误:

The backend starts fine (starts faster) but when the Angular project starts compiling and when the compilation is ready it throws the following error:

任何想法为什么?

这之前运行良好,遗憾的是我无法准确确定是什么变化导致了这种行为.在 NestJS 中我没有使用 cli,我只使用 tsc 构建它.

This has worked fine before, unfortunately I can not pinpoint exactly what changes caused this behavior. In NestJS I am not using the cli, I build it just with tsc.

WARNING in ../server/node_modules/@nestjs/common/utils/load-package.util.js 8:39-59
Critical dependency: the request of a dependency is an expression

ERROR in ../server/node_modules/@nestjs/common/cache/cache.providers.js
Module not found: Error: Can't resolve 'cache-manager' in '/mnt/c/codes/salesforce-compare/server/node_modules/@nestjs/common/cache'
ERROR in ../server/node_modules/@nestjs/common/pipes/validation.pipe.js
Module not found: Error: Can't resolve 'class-transformer' in '/mnt/c/codes/salesforce-compare/server/node_modules/@nestjs/common/pipes'
ERROR in ../server/node_modules/@nestjs/common/serializer/class-serializer.interceptor.js
Module not found: Error: Can't resolve 'class-transformer' in '/mnt/c/codes/salesforce-compare/server/node_modules/@nestjs/common/serializer'
ERROR in ../server/node_modules/@nestjs/common/pipes/validation.pipe.js
Module not found: Error: Can't resolve 'class-validator' in '/mnt/c/codes/salesforce-compare/server/node_modules/@nestjs/common/pipes'

推荐答案

看起来你的一些 Nestjs 包是在 Angular 应用程序中导入的.

Looks like some of your nestjs packages was imported in angular application.

我也遇到过这个问题.在我的例子中,我使用 @nestjs/swagger 中的 @ApiProperty 注释为后端和前端应用程序共享实体类.

I also encountered this issue. In my case, I shared entity classes with @ApiProperty annotations from @nestjs/swagger for both backend and frontend apps.

 
精彩推荐