Skip to content

ForkTsCheckerWebpackPlugin config kills build with fatal types error on badly typed test files #12045

Closed
@prndP

Description

@prndP

Describe the bug

I recently made a migration from CRA 3 to CRA 5 in my Typescript project and discovered the build had failed due to an errant test file. I fixed the types problem in the test file, but did not expect a behavior change in which a bad test type would cause CI build to fail, since CRA 3 build forgave badly typed tests.

I wondered if that was intentional breaking change, but did not see this in migration notes. After doing a little digging, I saw in the webpack config, the intent of the options passed into ForkTsCheckerWebpackPlugin appears to be unchanged, and is meant to exclude failed type check on test files from killing a build, since we see the exclusions { file: '**/src/**/?(*.){spec|test}.*' },. This makes sense to me, since I would expect tests to be relevant in react-scripts test step only.

However, this webpack config exclusion does not actually work due to the {spec|test} syntax. I confirmed this simply by creating a creating a brand new react-app on typescript just introducing a fatal type error in a .test.ts file within the project context and observe that it will fail the build.

Then I changed the config line { file: '**/src/**/?(*.){spec,test}.*' }, and observe that ForkTsCheckerWebpackPlugin appears to excludes test/spec files correctly.

Just a one line change, but has some implications of behavior changing re: whether or not type checks on tests should fail a build. I did not submit a PR to fix since I figured I would confirm intent in this report first.

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

ForkTsCheckerWebpackPlugin, TypeScript

Environment

System:
OS: macOS 11.6.3
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.3.1 - /usr/local/bin/npm
Browsers:
Chrome: 97.0.4692.71
Edge: 98.0.1108.43
Firefox: Not Found
Safari: 15.3

Steps to reproduce

  1. Use CRA to create a TypeScript repo
  2. Introduce a bad type to the existing .test.tsx file, ex. type Num = number; const a: Num = '';
  3. Run react-scripts build

Expected behavior

Expectation is tests are excluded from the types check, so the app build completes without failing since test files do not make it into the final bundle.

Actual behavior

Webpack exits with "Failed to compile"

Reproducible demo

Will do if requested, but should be really easy to reproduce with any existing repo on TS just by intentionally introducing a type error. I'd have to set up a repo with CI showing a failing build to demo this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions