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

Typescript check crashing vite serve

Open cwagner22 opened this issue 1 year ago • 10 comments

Describe the bug

There are no typescript errors but every time I start my vite server, it crashes after a few hmr updates. All I see is this:

node:internal/event_target:1090
  process.nextTick(() => { throw err; });
                           ^
Error: Debug Failure. False expression.
    at getOptionalType (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:70825:11)
    at tryReuseExistingTypeNode (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54296:16)
    at serializeTypeForDeclaration (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:56314:61)
    at addPropertyToElementList (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55284:43)
    at createTypeNodesFromResolvedType (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55180:11)
    at createTypeNodeFromObjectType (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54955:25)
    at visitAndTransformType (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54878:24)
    at createAnonymousTypeNode (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54818:20)
    at typeToTypeNodeWorker (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54611:16)
    at typeToTypeNodeHelper (/Users/c/project/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54392:24)

Node.js v22.7.0
Warning: command "vite serve" exited with non-zero status code

The getOptionalType function crashes on line Debug.assert(strictNullChecks) because I have strict: false in my tsconfig.

Reproduction

I haven't yet narrowed down a way to reproduce the issue because this is a nx monorepo. I will add it if I find a way. Here is the --showConfig output.

{
    "compilerOptions": {
        "rootDir": "../..",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node10",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "target": "es2021",
        "module": "esnext",
        "lib": [
            "es2021",
            "dom"
        ],
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "resolveJsonModule": true,
        "baseUrl": "./src",
        "paths": {
            "@ui/*": [
                "../../ui/src/*"
            ],
        },
        "strict": false,
        "jsx": "react-jsx",
        "allowJs": false,
        "esModuleInterop": false,
        "allowSyntheticDefaultImports": true,
        "jsxImportSource": "@emotion/react",
        "types": [
            "node",
            "@nx/react",
            "vite/client"
        ],
        "outDir": "../../dist/out-tsc",
        "noEmit": true
    },
    "files": [...],
    "include": [
        "src/**/*.js",
        "src/**/*.jsx",
        "src/**/*.ts",
        "src/**/*.tsx"
    ],
    "exclude": [
        "src/**/*.spec.ts"
    ]
}

Expected behavior

No crash

System Info

Node: 22.7.0
vite-plugin-checker: 0.8.0
typescript: 5.6.2

Additional context

checker({
  typescript: {
    tsconfigPath: 'tsconfig.app.json',
  },
})

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.

cwagner22 avatar Sep 12 '24 04:09 cwagner22

We're also getting this, but with webpack

Seems to be unrelated to vite and probably related to something in typescript 5.3+

Amnesthesia avatar Sep 24 '24 10:09 Amnesthesia

I'm seeing the same issue with vite in both typescript 5.6.2 and 5.2.2

spradlin-dev avatar Oct 06 '24 05:10 spradlin-dev

Also happening with typescript 5.7.2 and I haven't been able to find a solution for a long time.

gkonuralp avatar Dec 10 '24 14:12 gkonuralp

I've had this in my project for a while, although I don't know the root cause, the behaviour seems to be some sort of cache issue, because I can fix it by doing the following:

  • In the respective tsconfig, I have "strict": false". I flip this to true and run tsc again
  • I get a lot of TS errors but it runs successfully
  • I flip it to false again, and tsc runs fine now

Hopefully this helps as a temp fix even if it doesn't solve the root problem... Nevertheless it's really annoying having to do this multiple times a day just to be able to run a type check :(

Onurfesci avatar Jan 03 '25 14:01 Onurfesci

Note: Typescript v5.7.3 has fixed this issue for me!

Onurfesci avatar Jan 13 '25 13:01 Onurfesci

typescript 5.7.3 resolved the issue for me too

spradlin-dev avatar Jan 13 '25 14:01 spradlin-dev

TypeScript 5.7.3 is still NOT working for me. The ts-node version is 10.9.2, idk if this matters.

/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:121835
      throw e;
      ^

Error: Debug Failure. False expression.
    at Object.isUndefinedIdentifierExpression (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:50184:15)
    at typeFromExpression (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:131938:22)
    at serializeTypeOfExpression (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:131668:20)
    at Object.serializeTypeOfDeclaration (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:131692:16)
    at serializeTypeForDeclaration (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:52477:41)
    at addPropertyToElementList (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:51369:43)
    at createTypeNodesFromResolvedType (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:51265:11)
    at createTypeNodeFromObjectType (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:51032:25)
    at visitAndTransformType (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:50955:24)
    at createAnonymousTypeNode (/media/common/documents/Application Data/Nodejs/pnpm_global_ubuntu/5/.pnpm/[email protected]/node_modules/typescript/lib/_tsc.js:50895:20)

Node.js v22.13.0

NotYoojun avatar Feb 16 '25 05:02 NotYoojun

@NotYoojun can you provide a reproduction? 🙏

danielroe avatar Feb 18 '25 09:02 danielroe

@NotYoojun can you provide a reproduction? 🙏

I'm afraid no, we're having a really huge and complex project in our company and it's highly private.

But I can provide you some information, first this only happens in some of the projects, not all. Additionally, switching noEmit can temporarily fix this, but it will crash again later.

NotYoojun avatar Feb 18 '25 11:02 NotYoojun

@danielroe I'm sure that this issue is somehow not related to Vite or vite-plugin-checker, because when I'm using pure rollup to bundle libraries I encountered the same issue. However, there's a workaround to 'fix' it: https://github.com/microsoft/TypeScript/issues/60692#issuecomment-2772139204 (this requires dependency patch features)

You just need to always return true for the places where this crash happens.

NotYoojun avatar Apr 02 '25 10:04 NotYoojun