vite-plugin-checker icon indicating copy to clipboard operation
vite-plugin-checker copied to clipboard

Unwanted typescript errors when dev server is started

Open smtrd3 opened this issue 2 years ago • 11 comments

Describe the bug

Note that I am running vite under a monorepo setup, specifically using pnpm workspaces. I just bootstrapped the app with react-ts and vite-plugin-checker is the only plugin installed. I can see the following error

5:27:36 AM [vite] vite.config.ts changed, restarting server...
5:27:36 AM [vite] server restarted.

 ERROR(TypeScript)  Duplicate identifier 'Prepend'.
 FILE  /home/<USER>/project/node_modules/.pnpm/@[email protected]/node_modules/@types/eslint/helpers.d.ts:1:6

  > 1 | type Prepend<Tuple extends any[], Addend> = ((_: Addend, ..._1: Tuple) => any) extends (..._: infer Result) => any
      |      ^^^^^^^
    2 |     ? Result
    3 |     : never;
    4 |

 ERROR(TypeScript)  Duplicate identifier 'Prepend'.
 FILE  /home/<USER>/project/node_modules/.pnpm/@[email protected]/node_modules/@types/eslint/helpers.d.ts:1:6

  > 1 | type Prepend<Tuple extends any[], Addend> = ((_: Addend, ..._1: Tuple) => any) extends (..._: infer Result) => any
      |      ^^^^^^^
    2 |     ? Result
    3 |     : never;
    4 |

[TypeScript] Found 2 errors. Watching for file changes.

Screenshot: Screenshot 2022-03-31 at 11 15 59 AM

This is my config file:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import checker from 'vite-plugin-checker'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), checker({
    typescript: {
      root: '.', tsconfigPath: 'tsconfig.json'
    }
  })],
  server: {
    host: '0.0.0.0',
    port: 3000,
  }
})

Reproduction

  • add new module under a pnpm monorepo (with eslint being a dependency in other workspace packages)
  • start the dev server with the vite-plugin-checker plugin added

Expected behavior

The plugin should only typecheck source folder contents

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (2) x64 DO-Regular
    Memory: 482.94 MB / 3.84 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v14.17.0/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  npmPackages:
    vite-plugin-checker: ^0.4.4 => 0.4.4

Additional context

No response

Validations

  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

smtrd3 avatar Mar 31 '22 05:03 smtrd3

any issues reported by running tsc --noEmit?

fi3ework avatar Apr 05 '22 06:04 fi3ework

I got a similar issue with [email protected] and [email protected]. Turns out it was because skipLibCheck was set to true in my project tsconfig.json file.

val1984 avatar Apr 06 '22 15:04 val1984

@val1984 I think setting skipLibCheck to true can eliminate this report. And could you run tsc --noEmit in your project to verify is it the right report from tsc?

fi3ework avatar Apr 06 '22 15:04 fi3ework

Sorry, I wasn't clear in my previous message but it definitely fixed the issue for me.

@smtrd3 Can you try this solution?

val1984 avatar Apr 06 '22 16:04 val1984

For anyone who encounters similar issues. You can run tsc --noEmit or vue-tsc --noEmit under your project. If the command reports the same issues, then there's nothing to do with vite-plugin-checker cause it just forwards the issues. If not, please leave a comment below.

fi3ework avatar Apr 06 '22 16:04 fi3ework

I am having the same problem, in my case I am getting way more erros from node_modules libs:

My configuration is basic a copy from stackblitz example (react)

image image

guiphc avatar May 05 '22 22:05 guiphc

@guiphc add skipLibCheck: true to tsconfig

fi3ework avatar May 06 '22 03:05 fi3ework

@guiphc add skipLibCheck: true to tsconfig

this did not work, for some reason looks like the plugin did not respect my tsconfig.

guiphc avatar May 06 '22 03:05 guiphc

@guiphc Provide a stackblitz link please

fi3ework avatar May 06 '22 04:05 fi3ework

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a bug report, please provide a minimal re-production repository or use path to reproduce. Thank you for your contributions.

stale[bot] avatar Jul 05 '22 09:07 stale[bot]

I'm kind of experiencing this as well, though it's more of a bonus than a bug for me. If I run tsc --noEmit the errors that are being reported by the plugin are indeed picked up by TypeScript, but these errors aren't reported in the IDE (VS Code). I know Vite doesn't really care, but they're of course not reported during the vite build process as well, meaning I probably never would have caught these if I wasn't using the plugin. (❤️)

Is this a TypeScript bug, a VS Code bug or? Any hints on how I can make sure that these bugs are reported in the IDE as well?

TurtIeSocks avatar Jul 14 '22 12:07 TurtIeSocks