Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript file in __tests__ with incorrect extension causes unrelated errors to be ignored in yarn build #9160

Closed
mungojam opened this issue Jun 15, 2020 · 9 comments

Comments

@mungojam
Copy link

mungojam commented Jun 15, 2020

Describe the bug

We're in the middle of a conversion to typescript and found that noImplicitAny errors weren't getting reported in react-scripts build which was incorrectly succeeding.

I've now isolated the cause which is a very odd one based on the presence of any typescript files with incorrect extensions in __tests__ directories. To be clear, the errors that should be getting reported are in regular react files/directories, not the __tests__ folder (i.e. this isn't the same as #5626).

So if there is a file containing jsx with the incorrect extension ts instead of tsx, and it is in a __tests__ folder, then all noImplicitAny errors get blotted out wherever they are and react-scripts build succeeds.

VS Code reports the errors throughout.

Did you try recovering your dependencies?

Yes

yarn --version:

2.0.0-rc.35

Which terms did you search for in User Guide?

typescript, noImplicitAny

Environment

Environment Info:

current version of create-react-app: 3.4.1
running from C:\Users\me\AppData\Local\Yarn\Data\global\node_modules\create-react-app

System:
OS: Windows 10 10.0.17134
CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
Binaries:
Node: 12.14.1 - C:\Program Files\nodejs\node.EXE
Yarn: 2.0.0-rc.35 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 42.17134.1098.0
Internet Explorer: 11.0.17134.1
npmPackages:
react: Not Found
react-dom: Not Found
react-scripts: Not Found
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

  1. Standard create-react-app with typescript
  2. In the App.tsx add a function with a parameter without a type (e.g. const someFunc = a => a) and use it in the app component.
  3. yarn build and you will see the correct noImplicitAny error.
  4. Add a file with a .ts (not .tsx) extension to the __tests__ folder. Make the file a valid tsx file by importing react and adding some jsx like const a = <div />
  5. yarn build, which will now succeed without errors or warnings even though our App.jsx still has a clear typescript error in it.
  6. Move the .ts file out of the tests folder into a regular folder and yarn build then correctly gives an error due to the wrong file extension.
    or
    6b. Rename the .ts file to have a .tsx extension and then yarn build gives the correct error as in step 3.

See my reproducible example on GitHub below.

Expected behavior

It should either give the typescript parse error due to incorrect extension which shows when moving the file out of __tests__, or it should give the noImplicitAny error that shows when correcting the file extension to tsx but leaving in __tests__.

Ideally the first, but that may not be possible yet due to #5626.

Actual behavior

yarn build reports no errors and builds successfully despite there being a clear typescript error in the index.tsx file. The error is correctly reported if the __tests__ folder is deleted or if the file in it is renamed to have the correct .tsx extension.

Reproducible demo

https://github.com/mungojam/MRE-Typescript-Non-Error

  1. clone the repo
  2. yarn install (we use yarn 2, but you can presumably make it work with yarn 1)
  3. yarn build

The build succeeds, when it should fail.

Then to make it correctly fail, either switch to either of the other branches, or manually:

  1. Correct the src/__tests__/a.ts file extension to tsx
  2. yarn build which then gives the correct error about noImplicitAny in index.tsx.

Or

  1. Move the src/__tests__/a.ts file extension to the src folder.
  2. yarn build which then gives the correct error about the file not being parsable, because it has jsx in it with the wrong file extension.
@stale
Copy link

stale bot commented Jul 18, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jul 18, 2020
@mungojam
Copy link
Author

Please leave open and fix, it's a big gotcha that let linting issues get to production in our case

@stale stale bot removed the stale label Jul 18, 2020
@stale
Copy link

stale bot commented Aug 22, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Aug 22, 2020
@mungojam
Copy link
Author

Feels like a major issue to us

@stale stale bot removed the stale label Aug 23, 2020
@stale
Copy link

stale bot commented Oct 4, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Oct 4, 2020
@mungojam
Copy link
Author

mungojam commented Oct 4, 2020

let's just hope we don't allow errors through to production because of this

@stale stale bot removed the stale label Oct 4, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 25, 2020
@iansu
Copy link
Contributor

iansu commented May 19, 2021

TypeScript does not support JSX inside of a .ts file, only .tsx files.

@mungojam
Copy link
Author

mungojam commented May 19, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants