Absolute paths lead to "Error: Cannot find module" since introduction of native TypeScript support in Cypress@4.4.0
Absolute paths lead to "Error: Cannot find module" since introduction of native TypeScript support in Cypress@4.4.0
项目
我有一个包含大约 100 个 ui 测试的网络应用程序,我想摆脱 cypress-webpack-preprocessor,因为在 Cypress@4.4.0 中原生添加了 typescript 支持。我已更新到最新版本的 Cypress,但无法再在我的测试中使用绝对路径 - 我想这应该是可能的。
问题
虽然这有效
import { DateFormatter } from "./../../../../src/util/formatter/date-formatter";
这不是
import { DateFormatter } from "src/util/formatter/date-formatter";
无论我在 tsconfig.json
中更改什么,它总是显示此错误消息
Error: Cannot find module '<file in my project>' from '<path to my test file>'
可重现的例子
为了测试这一点,我遵循了最小 Cypress - TypeScript example until the section Tip: Sharing code between UI and test 的说明,它工作得很好,但如果我用绝对路径替换相对路径,它就不再工作了。
这是一个github non-working example
编辑:进一步研究
我发现这个 cypress 问题 typescript compilerOptions not reflected and this comment 表明 cypress 忽略了 tsconfig.json complierOptions
因此无法添加 baseUrl
和 paths
选项。
项目
我有一个包含大约 100 个 ui 测试的网络应用程序,我想摆脱 cypress-webpack-preprocessor,因为在 Cypress@4.4.0 中原生添加了 typescript 支持。我已更新到最新版本的 Cypress,但无法再在我的测试中使用绝对路径 - 我想这应该是可能的。
问题
虽然这有效
import { DateFormatter } from "./../../../../src/util/formatter/date-formatter";
这不是
import { DateFormatter } from "src/util/formatter/date-formatter";
无论我在 tsconfig.json
中更改什么,它总是显示此错误消息
Error: Cannot find module '<file in my project>' from '<path to my test file>'
可重现的例子
为了测试这一点,我遵循了最小 Cypress - TypeScript example until the section Tip: Sharing code between UI and test 的说明,它工作得很好,但如果我用绝对路径替换相对路径,它就不再工作了。
这是一个github non-working example
编辑:进一步研究
我发现这个 cypress 问题 typescript compilerOptions not reflected and this comment 表明 cypress 忽略了 tsconfig.json complierOptions
因此无法添加 baseUrl
和 paths
选项。