You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ForkTsCheckerWebpackPluginappears 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.
Introduce a bad type to the existing .test.tsx file, ex. type Num = number; const a: Num = '';
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.
The text was updated successfully, but these errors were encountered:
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 inreact-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 thatForkTsCheckerWebpackPlugin
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
type Num = number; const a: Num = '';
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.
The text was updated successfully, but these errors were encountered: