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

Error: [birpc] timeout on calling "fetch" #5182

Closed
6 tasks done
Maxim-Mazurok opened this issue Feb 11, 2024 · 17 comments
Closed
6 tasks done

Error: [birpc] timeout on calling "fetch" #5182

Maxim-Mazurok opened this issue Feb 11, 2024 · 17 comments
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) upstream

Comments

@Maxim-Mazurok
Copy link
Contributor

Maxim-Mazurok commented Feb 11, 2024

Describe the bug

Getting Error: [birpc] timeout on calling "fetch" repeatedly after upgrading

Reproduction

https://github.com/Maxim-Mazurok/vite-repro

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 27.99 GB / 63.68 GB
  Binaries:
    Node: 20.10.0 - ~\AppData\Local\nvs\node\20.10.0\x64\node.EXE
    npm: 10.2.3 - ~\AppData\Local\nvs\node\20.10.0\x64\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.83)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitest/coverage-v8: 1.0.4 => 1.0.4
    @vitest/ui: 1.0.4 => 1.0.4
    vite: >=5.1.1 => 5.1.1
    vitest: 1.0.4 => 1.0.4

Used Package Manager

npm

Validations

@Maxim-Mazurok
Copy link
Contributor Author

This is happening for 2/20 nx projects I have.
And only happens on vite 5.1.x but works fine on 5.0.x

@ikar1234
Copy link

If you want a quick fix, and your setup allows it, you can try #4106 (comment), This worked for us.

@Maxim-Mazurok
Copy link
Contributor Author

If you want a quick fix, and your setup allows it, you can try #4106 (comment), This worked for us.

I'm getting timeout on high-end PC, not in CI/CD:
Processor 12th Gen Intel(R) Core(TM) i9-12900H 2.50 GHz
Installed RAM 64.0 GB (63.7 GB usable)

I've tried to increase timeout as suggested, but it doesn't help. 3/20 projects just hang on vite with zero activity, clearly not a performance issue, they aren't even trying to run as far as I can tell

Copy link

Hello @Maxim-Mazurok. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@ak274
Copy link

ak274 commented Feb 12, 2024

I'm also facing this error while running tests in a nx wprkspace with vite@5.1.1 but working fine with vite@5.0.12

@pongells
Copy link

pongells commented Feb 12, 2024

same error here with vite 5.1.1

@Maxim-Mazurok
Copy link
Contributor Author

Some more reproduction help:

It doesn't repro when I only have 1 test/spec file in the project.

If I have 2 test/spec files (even if they are empty) - I get a stable reproduction.

I am running an individual project (nx run utils:test) not in parallel.

Here's my vite.config.ts for the project:

import { defineConfig } from "vite";
import { merge } from "ts-deepmerge";
import viteTsConfigPaths from "vite-tsconfig-paths";
// eslint-disable-next-line @nx/enforce-module-boundaries
import { myDefaultUserConfig } from "../../vite-stuff";

export default defineConfig(
  merge(myDefaultUserConfig, {
    cacheDir: "../../node_modules/.vite/math",

    plugins: [
      viteTsConfigPaths({
        root: "../../",
      }),
    ],

    test: {
      cache: {
        dir: "../../node_modules/.vitest",
      },
      environment: "node",
      include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
    },
  }),
);

Here's my vite-stuff.ts:

import { fileURLToPath } from "node:url";
import viteTsConfigPaths from "vite-tsconfig-paths";
import { UserConfig } from "vitest/config";
// import { pathToResources } from "@nx/nx-utils"; // TODO: figure out how to re-arrange imports
//@ts-expect-error doesn't matter, seems to work fine
const pathToResources = new URL("resources/", import.meta.url);

interface MyUserConfig extends UserConfig {
  plugins: Required<UserConfig["plugins"]>;
  test: Required<
    Pick<
      Exclude<Required<UserConfig["test"]>, undefined>,
      "globals" | "restoreMocks" | "reporters"
    > & {
      setupFiles: Exclude<
        Pick<
          Exclude<Required<UserConfig["test"]>, undefined>,
          "setupFiles"
        >["setupFiles"],
        string
      >;
    }
  >;
}

export const myDefaultUserConfig: MyUserConfig = {
  plugins: [viteTsConfigPaths()],
  test: {
    globals: true,
    setupFiles: [
      fileURLToPath(new URL("setupFiles/toEqual.ts", pathToResources)), // requires server.fs.strict to be false to work
    ],
    restoreMocks: false, // TODO: enable this, but beware of issues with vi.mock tho (TypeError: Class constructor GoogleSheetsDownloader cannot be invoked without 'new')
    reporters: ["default"],
  },
  server: {
    fs: {
      strict: false, // this will allow to load setup file from resources
    },
  },
};

Hope this helps to resolve the issue, cheers!

@mwood23
Copy link

mwood23 commented Feb 13, 2024

Same, two spec files and it breaks reliably.

@Maxim-Mazurok
Copy link
Contributor Author

Hello @Maxim-Mazurok. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

Added reproduction on a clean nx setup, see readme for steps I took to set it up: https://github.com/Maxim-Mazurok/vite-repro

@sheremet-va
Copy link
Member

sheremet-va commented Feb 13, 2024

This is an issue with how Vite resolves tsconfigs:

@sheremet-va sheremet-va added bug upstream p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Feb 13, 2024
@sheremet-va
Copy link
Member

By the way, the workaround is to remove references from tsconfig:

{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "module": "commonjs",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true
  },
  "files": [],
  "include": [],
-  "references": [
-    {
-      "path": "./tsconfig.lib.json"
-    },
-    {
-      "path": "./tsconfig.spec.json"
-    }
-  ]
}

@daihere1993
Copy link

daihere1993 commented Feb 26, 2024

I'm facing the exactly same issue while using nx with vitest. I'm using newer vitest then the error message would be:
"Error: [vitest-worker]: Timeout calling "fetch" with "["/xxxx/demo_repos/vite-repro/bla/src/lib/bla.spec.ts","ssr"]""

which modified by #5103

Take https://github.com/Maxim-Mazurok/vite-repro as an example, the better W/A would be to modify the extends of tsconfig.spec.json and tsconfig.lib.json to "extends": "../tsconfig.base.json" from "extends": "./tsconfig.json" to avoid the known issue dominikg/tsconfck#154 @sheremet-va mentioned.

Details of W/A:

diff --git a/bla/tsconfig.lib.json b/bla/tsconfig.lib.json
index 2fd1e3f..4d0c527 100644
--- a/bla/tsconfig.lib.json
+++ b/bla/tsconfig.lib.json
@@ -1,5 +1,5 @@
 {
-  "extends": "./tsconfig.json",
+  "extends": "../tsconfig.base.json",
   "compilerOptions": {
     "outDir": "../dist/out-tsc",
     "declaration": true,
diff --git a/bla/tsconfig.spec.json b/bla/tsconfig.spec.json
index 4f7fed6..3e6ed46 100644
--- a/bla/tsconfig.spec.json
+++ b/bla/tsconfig.spec.json
@@ -1,5 +1,5 @@
 {
-  "extends": "./tsconfig.json",
+  "extends": "../tsconfig.base.json",
   "compilerOptions": {
     "outDir": "../dist/out-tsc",
     "types": [

@Maxim-Mazurok FYI

@chinanderm
Copy link

@daihere1993 I am running into the same problem in my Nx repo with vite 5.1.x and vitest 1.3.x. In the workaround you suggested, that is the exact structure of the tsconfig files in our repo and the issue remains. You can further clarify this workaround?

@daihere1993
Copy link

daihere1993 commented Feb 27, 2024

@daihere1993 I am running into the same problem in my Nx repo with vite 5.1.x and vitest 1.3.x. In the workaround you suggested, that is the exact structure of the tsconfig files in our repo and the issue remains. You can further clarify this workaround?

The issue we facing is a known issue(dominikg/tsconfck#154) of tsconfck which is a dependency package of vite to parse tsconfig files.

tsconfig.base.json
/apps/{your_app}/tsconfig.json # references ['./tsconfig.app.json', 'tsconfig.spec.json']
/apps/{your_app}/tsconfig.app.json # extends './tsconfig.json'
/apps/{your_app}/tsconfig.spec.json # extends './tsconfig.json'

Above is a typical structure and typescript configuration of nx app with vitest. As you can see the tsconfig.json refer to tsconfig.app.json and tsconfig.spec.json then both of them extend back to tsconfig.json. The current implementation of tsconfck can not handle such "circle" configuration which will cause a deadlock situation in which referenced file and extended file would await the parsing of each other then timeout happened.

Thus the W/A I suggested is to avoid such "circle", and just extends tsconfig.base.json directly.

@chinanderm
Copy link

@daihere1993 Ah, apologies, I misread the extends in your original post which caused my confusion. Thanks for pointing that out. Makes sense.

@viceice
Copy link

viceice commented Mar 11, 2024

strange, for me only --pool=forks cli option works, setting it inside vitest.config.js has no effect.

@sapphi-red
Copy link
Contributor

The fix on Vite side is released in 5.1.6 (vitejs/vite#16124).

@sheremet-va sheremet-va removed their assignment Mar 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.