【问题标题】:File is not under 'rootDir' in Cypress tsconfig.json文件不在赛普拉斯 tsconfig.json 中的“rootDir”下
【发布时间】:2022-01-01 07:57:26
【问题描述】:

我正在尝试在我的项目中配置赛普拉斯。我遇到了 Cypress 的 typescript 配置问题,需要您的帮助! 这是我的项目的样子:

fronend/
    - cypress/
        -tsconfig.json
    - src/
    - tsconfig.json
    - package.json
    - cypreess.json

这是我来自 Cypress 目录的 tsconfig.json:

{
  "extends": "../tsconfig.json",
  "include": ["./**/*.ts"],
  "exclude": [],
  "compilerOptions": {
    "types": ["cypress"],
    "lib": ["es2015", "dom"],
    "isolatedModules": false,
    "composite": true
  }
}

这是我前端目录中的 tsconfig.json 文件:

{
  "compilerOptions": {
    "baseUrl": "src",
    "rootDir": "src",
    "target": "es6",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": ["./src/**/*.ts", "./src/**/*.tsx", "./src/**/*.svg"],
  "exclude": ["node_modules", "scripts"],
  "references": [
    {
      "path": "./cypress/"
    }
  ]
}

没有"extends": "../tsconfig.json",Cypress 也可以正常工作,但我需要它,因为我想在 cypress ts 文件中从 src 目录导出文件。

您能告诉我我的配置有什么问题吗? 我宁愿不要更改主 tsconfig.json 文件,因为它运行我们的 UI。 这是我的错误:

File '/**/fronend/cypress/support/objects/client.ts' is not under 'rootDir' '/**/frontend/src'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Imported via '../../support/client' from file '/**/frontend/cypress/integration/EndToEndTests.spec.ts'
    Matched by include pattern './**/*.ts' in '/**/frontend/cypress/tsconfig.json'ts(6059)
tsconfig.json(3, 15): File is matched by include pattern specified here.

【问题讨论】:

    标签: typescript react-native configuration cypress


    【解决方案1】:

    您的问题是由于cypress 文件夹的全部内容不包含在src 下。设置cypress/tsconfig.json文件时,可以覆盖父tsconfig.json文件中设置的rootDir属性。

    尝试将该字段设置为 cypress 目录。

    ...
    "compilerOptions: {
        "rootDir": "./"
        ...
    },
    ...
    

    ^ 上述方法可能有效,因为tsconfig 位于cypress 目录中。

    【讨论】:

    • 谢谢!它有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 2023-02-14
    • 2021-12-02
    • 2020-12-23
    • 2020-10-26
    • 2023-02-05
    相关资源
    最近更新 更多