' rxjs'在运行开玩笑测试套件时找不到模块
我有一个Nest JS应用程序,我正在为某些提供商类编写测试。 beforeall fn。在我的 *.spec.ts文件中定义的开玩笑的运行良好,但开玩笑()fn。失败带有以下错误:
Cannot find module 'rxjs' from 'node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js'
Require stack:
node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js
node_modules/@nestjs/common/cache/interceptors/index.js
node_modules/@nestjs/common/cache/index.js
node_modules/@nestjs/common/index.js
node_modules/@nestjs/testing/testing-module.builder.js
node_modules/@nestjs/testing/test.js
node_modules/@nestjs/testing/index.js
src/bookmark/test/integration/bkm.service.int-spec.ts
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:491:11)
at Object.<anonymous> (node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js:5:16)
我的package.json在“依赖关系”部分中定义了带有 ^7.2.0版本的RXJ。
我在 *.spec.ts测试类中的测试看起来像这样:
describe('BookmarkService Integration', () => {
let prisma: PrismaService;
let bookmarkService: BookmarkService
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile();
prisma = moduleRef.get(PrismaService);
bookmarkService = moduleRef.get(BookmarkService);
await prisma.cleanDatabase();
});
it.todo('Default test pass')
})
我没有尝试明确执行RXJ的NPM安装,因为当我初始化嵌套时,当它已经作为默认的依赖性时,我不理解安装它的后果应用。任何帮助将不胜感激。
谢谢
I have a Nest JS application for which I am writing tests for some of the Provider classes. The beforeAll fn. of jest defined in my *.spec.ts file runs fine but the jest todo() fn. fails with the following error:
Cannot find module 'rxjs' from 'node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js'
Require stack:
node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js
node_modules/@nestjs/common/cache/interceptors/index.js
node_modules/@nestjs/common/cache/index.js
node_modules/@nestjs/common/index.js
node_modules/@nestjs/testing/testing-module.builder.js
node_modules/@nestjs/testing/test.js
node_modules/@nestjs/testing/index.js
src/bookmark/test/integration/bkm.service.int-spec.ts
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:491:11)
at Object.<anonymous> (node_modules/@nestjs/common/cache/interceptors/cache.interceptor.js:5:16)
My package.json has rxjs defined in the "dependencies" section with a version of ^7.2.0.
My test in the *.spec.ts testing class looks like this:
describe('BookmarkService Integration', () => {
let prisma: PrismaService;
let bookmarkService: BookmarkService
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile();
prisma = moduleRef.get(PrismaService);
bookmarkService = moduleRef.get(BookmarkService);
await prisma.cleanDatabase();
});
it.todo('Default test pass')
})
I have not tried explicitly doing a npm install of rxjs since I don't understand the consequence of installing it when it already came as a default dependency when I initialized my Nest application. Any help would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找不到模块
是一个常见的错误,当您的项目代码请求或导入的模块之一由一个导入的模块所请求的依赖项无法找到node_module
目录中的目标模块。这个问题可能是由多种情况引起的,但是根据您对我的评论的回应,这可能是由于
npm
已缓存package> package> package-lock.json 属性以及重新启动
npm安装
仍然会将错误的模块添加到node_modules
Directory。因此,分辨率是node_modules
目录的简单删除,package> package> package-lock.json
文件和npm install的重读
命令。要回答您关于这仍然是一个问题的问题,即使
package-lock.json
确实包含rxjs
库参考,我可能会有很多我会这样必须推测;一方面,您正在检查的内容可能是 transiverxjs
依赖项,而不是另一个库使用,而不是rxjs
库实际上是在错误中要求的。另外,即使rxjs
在package> package-lock.json
文件中定义,但实际上可能没有在node_modules 目录可能无法安装。这实际上取决于您在看到问题之前所做的事情的确切顺序,但我希望我的解释阐明了您面临的问题。
Cannot find module
is a common error that is thrown when a dependency requested by your project code or by one of the imported modules cannot find the target module inside thenode_module
directory.This issue can be caused by a multitude of scenarios, but going by your response to my comment, it was likely caused by the fact that
npm
had cached thepackage-lock.json
properties and upon rerunningnpm install
would still add incorrect modules to thenode_modules
directory. Hence the resolution is a simple deletion of thenode_modules
directory, thepackage-lock.json
file and the rerunning of thenpm install
command.To answer your question on how this was still a problem even when
package-lock.json
did contain therxjs
library reference, there could have been a number of scenarios that I would have to speculate; for one, what you were inspecting could have been a transitiverxjs
dependency which is being used by another library and is not therxjs
library that is actually being requested for in the error. Alternatively, there is a chance that even thoughrxjs
was defined in thepackage-lock.json
file, it may not have actually been present in thenode_modules
directory as it may have failed to install. This really depends on the exact sequence of things that you have done prior to seeing the issue, but I hope my explanation clarifies the problem you were facing.