vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.45k stars 6.07k forks source link

tsc --noEmit does not detect issues in react-ts template #17585

Closed JElgar closed 2 months ago

JElgar commented 3 months ago

Describe the bug

After adding type errors in project tsc not showing any errors when run (npx tsc -w) in react-ts template.

Reproduction

https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts

Steps to reproduce

  1. Clone https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts or open https://vite.new/react-ts
  2. Open src/main.tsx and add const a: string = 2 somewhere
  3. Run npx tsc --noEmit

tsc will say there is no issue (when it should be complaining about the line we just added

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    vite: ^5.3.1 => 5.3.2

Used Package Manager

npm

Logs

~/projects/vitejs-vite-whkhm3 2s ❯ npx tsc --noEmit

^ there is no output

Validations

sapphi-red commented 3 months ago

You need to run tsc -b instead of tsc --noEmit.

But that might be not intuitive. Maybe this could be one reason to revert #15913 and merge the tsconfigs (https://github.com/vitejs/vite/pull/15913#:~:text=Maybe%20removing%20tsconfig.node.json%20and%20adding%20vite.config.ts%20to%20include%20of%20tsconfig.json%20is%20better%3F%20%F0%9F%A4%94%20It%20doesn%27t%20have%20much%20benefit%20of%20having%20it%20in%20the%20current%20state%20(%2311396%20(comment))).

MehYam commented 3 months ago

Probably just repeating OP here, but the same holds for those of us using tsc -w as our compile error monitor. I just created a new Typescript + React project with npm create vite@latest, and tsc -w seems to have trouble unless I merge the tsconfigs myself.

JElgar commented 2 months ago

You need to run tsc -b

Thanks that does the trick!

But that might be not intuitive

I agree, having a root tsconfig with no included files and then 2 tsconfigs both marked with no emit takes a bit of getting used to. That being said I'm not super familiar with this stuff so that might just be me.

bluwy commented 2 months ago

Closing this as the issue is of the missing -b flag not passed, and not an issue with the template in general. However, we have been discussing and working on removing the "solutions" setup, which had caused other confusions like https://github.com/vitejs/vite/issues/17638