【发布时间】:2022-12-03 16:16:05
【问题描述】:
我在/src/common/helper/cash.helper.ts 中有一些辅助函数。当我从模块调用此函数时,出现以下错误。
Error: Cannot find module './../../../src/common/helper/cast.helper' Require stack:
但是,e2e 测试没有任何问题。在这里,您可以看到文件夹结构。
当我将导入更改为绝对路径import { toNumber } from 'src/common/helper/cast.helper'时;它在工作,但 e2e 测试不工作。
这里出了什么问题?如何在 NestJS 的所有模块中使用通用函数和常量?
【问题讨论】:
-
不要使用绝对路径。否则你需要在 jest 配置文件中设置
moduleNameMapper。 -
你应该可以做 src/common/helper/cast.helper 不?