Build with vitest got error: `Cannot find module 'node:http' or its corresponding type declarations.`

Viewed 19

I added vitest in package.json: "vitest": "^0.23.4",

After that, the test is Ok. however when I run the build, I got many error like following:

ERROR in /Users/jianwu.chen/opensource/TreedocViewer/node_modules/vite/dist/node/index.d.ts(3,28):
3:28 Cannot find module 'node:http' or its corresponding type declarations.
    1 | /// <reference types="node" />
    2 | 
  > 3 | import type { Agent } from 'node:http';
      |                            ^

Not sure why only vite has this problem. As a work around, I exclude the test folder in tsconfig.js:

  "exclude": [
    "tests/**/*.tsx",
    "tests/**/*.ts"
    "node_modules"
  ]

That can make build pass. But not understanding why I have to exclude those tests depends on vitest which in turn depends on vite.

[updated with additional information]

~/opensource/TreedocViewer $ npm ls @types/node
treedoc-viewer@0.1.43 /Users/jianwu.chen/opensource/TreedocViewer
├─┬ @vue/cli-plugin-typescript@4.5.17
│ └─┬ globby@9.2.0
│   └─┬ @types/glob@7.1.3
│     └── @types/node@14.14.22 deduped
├─┬ @vue/cli-service@4.5.17
│ ├─┬ @types/webpack-dev-server@3.11.1
│ │ ├─┬ @types/connect-history-api-fallback@1.3.3
│ │ │ ├─┬ @types/express-serve-static-core@4.17.18
│ │ │ │ └── @types/node@14.14.22 deduped
│ │ │ └── @types/node@14.14.22 deduped
│ │ ├─┬ @types/express@4.17.11
│ │ │ └─┬ @types/body-parser@1.19.0
│ │ │   └── @types/node@14.14.22 deduped
│ │ ├─┬ @types/http-proxy-middleware@0.19.3
│ │ │ ├─┬ @types/connect@3.4.34
│ │ │ │ └── @types/node@14.14.22 deduped
│ │ │ ├─┬ @types/http-proxy@1.17.5
│ │ │ │ └── @types/node@14.14.22 deduped
│ │ │ └── @types/node@14.14.22 deduped
│ │ └─┬ @types/serve-static@1.13.9
│ │   └── @types/node@14.14.22 deduped
│ └─┬ @types/webpack@4.41.26
│   ├── @types/node@14.14.22 deduped
│   └─┬ @types/webpack-sources@2.1.0
│     └── @types/node@14.14.22 deduped
├─┬ ts-node@10.7.0
│ └── @types/node@14.14.22
├─┬ vitest@0.23.4
│ └── @types/node@14.14.22 deduped
└─┬ vue-cli-plugin-e2e-webdriverio@2.0.3
  ├─┬ chromedriver@105.0.1
  │ └─┬ extract-zip@2.0.1
  │   └─┬ @types/yauzl@2.9.1
  │     └── @types/node@14.14.22 deduped
  └─┬ webdriverio@5.23.0
    └─┬ webdriver@5.23.0
      └─┬ @types/request@2.48.5
        └── @types/node@14.14.22 deduped
0 Answers
Related