create-react-app 在运行 start 命令时,react-scripts v5 对测试文件进行类型检查,

13z8s7eq  于 2个月前  发布在  React
关注(0)|答案(1)|浏览(30)

描述bug

在升级到react-scripts v5时,运行react-scripts startreact-scripts build的任何.test.ts.spec.ts文件中的类型错误会被报告给构建过程,导致构建失败。

你是否尝试恢复依赖项?

我启动了一个新项目来重现错误,但bug仍然存在

你在用户指南中搜索了哪些术语?

Typescript, types, tests.

环境

Environment Info:

  current version of create-react-app: 5.0.0
  running from /Users/joewalton/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 16.13.1 - ~/.asdf/installs/nodejs/16.13.1/bin/node
    Yarn: 1.22.17 - ~/.asdf/installs/nodejs/16.13.1/.npm/bin/yarn
    npm: 8.1.2 - ~/.asdf/installs/nodejs/16.13.1/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Edge: Not Found
    Firefox: Not Found
    Safari: 15.1
  npmPackages:
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    react-scripts: ^5.0.0 => 5.0.0
  npmGlobalPackages:
    create-react-app: Not Found

重现步骤

  1. 使用typescript模板创建一个新的create-react-app。 npx create-react-app my-app --template typescript
  2. src/App.test.tsx中添加一个类型错误。
  3. 运行npm run build

预期行为

在运行或构建应用程序代码时,测试文件中的类型错误应被忽略。

实际行为

在运行或构建应用程序代码时,测试文件中的类型错误会被报告。

可复现示例

https://github.com/jwalton9/cra-test-type-error

8aqjt8rx

8aqjt8rx1#

同样的问题,除此之外,通常 @ts-ignore@ts-expect-error 可以正常工作,但在 .test 文件中无法正常工作,它们被忽略了,但在主代码中仍然可以正常工作。
因此,我认为当运行测试时,存在一些配置差异,它可能会忽略linting插件?或者这些插件已经过时,不支持测试环境?

相关问题