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

tsconfig.node.json should not be included in tsconfig.json references #11396

Closed
7 tasks done
FabianFrank opened this issue Dec 16, 2022 · 9 comments · Fixed by #15913
Closed
7 tasks done

tsconfig.node.json should not be included in tsconfig.json references #11396

FabianFrank opened this issue Dec 16, 2022 · 9 comments · Fixed by #15913

Comments

@FabianFrank
Copy link

FabianFrank commented Dec 16, 2022

Describe the bug

The reason I stumbled upon this is because I am using TypeScript Project References and tsc --build fails with a few type errors like

node_modules/@types/scheduler/tracing.d.ts:102:40 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

102 export function unstable_getCurrent(): Set<Interaction> | null;
                                           ~~~

node_modules/@types/react/index.d.ts:230:10 - error TS2456: Type alias 'ReactFragment' circularly references itself.

230     type ReactFragment = Iterable<ReactNode>;
             ~~~~~~~~~~~~~

in the blank React TypeScript template.

That said, removing { "path": "./tsconfig.node.json" } from tsconfig.json does neither seem to break npm run dev nor npm run build in the template and then allows tsc --build to complete successfully. It doesn't seem like anything actually expects this include to exist? #6324 doesn't regress for me with the line removed.

Reproduction

https://stackblitz.com/edit/vite-react-ts?file=package.json

Steps to reproduce

Open https://stackblitz.com/edit/vite-react-ts?file=package.json and run tsc --build in the terminal

Screenshot 2022-12-16 at 1 04 48 AM

System Info

stackblitz

Used Package Manager

npm

Logs

~/projects/vite-react-ts
❯ tsc --build
node_modules/rollup/dist/rollup.d.ts:199:22 - error TS2304: Cannot find name 'IterableIterator'.

199  getModuleIds: () => IterableIterator<string>;
                         ~~~~~~~~~~~~~~~~

node_modules/rollup/dist/rollup.d.ts:208:13 - error TS2304: Cannot find name 'IterableIterator'.

208  moduleIds: IterableIterator<string>;
                ~~~~~~~~~~~~~~~~

node_modules/rollup/dist/rollup.d.ts:522:22 - error TS2304: Cannot find name 'IterableIterator'.

522  getModuleIds: () => IterableIterator<string>;
                         ~~~~~~~~~~~~~~~~

node_modules/postcss/lib/lazy-result.d.ts:60:28 - error TS2339: Property 'finally' does not exist on type 'Promise<Result>'.

60   finally: Promise<Result>['finally']
                              ~~~~~~~~~

node_modules/postcss/lib/lazy-result.d.ts:73:8 - error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

73   get [Symbol.toStringTag](): string
          ~~~~~~

node_modules/postcss/lib/no-work-result.d.ts:23:28 - error TS2339: Property 'finally' does not exist on type 'Promise<Result>'.

23   finally: Promise<Result>['finally']
                              ~~~~~~~~~

node_modules/postcss/lib/no-work-result.d.ts:25:8 - error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

25   get [Symbol.toStringTag](): string
          ~~~~~~

node_modules/vite/dist/node/index.d.ts:3:28 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

3 import type { Agent } from 'http';
                             ~~~~~~

node_modules/vite/dist/node/index.d.ts:5:36 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

5 import type { ClientRequest } from 'http';
                                     ~~~~~~

node_modules/vite/dist/node/index.d.ts:6:40 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

6 import type { ClientRequestArgs } from 'http';
                                         ~~~~~~

node_modules/vite/dist/node/index.d.ts:8:29 - error TS2307: Cannot find module 'stream' or its corresponding type declarations.

8 import type { Duplex } from 'stream';
                              ~~~~~~~~

node_modules/vite/dist/node/index.d.ts:9:36 - error TS2307: Cannot find module 'stream' or its corresponding type declarations.

9 import type { DuplexOptions } from 'stream';
                                     ~~~~~~~~

node_modules/vite/dist/node/index.d.ts:11:30 - error TS2307: Cannot find module 'events' or its corresponding type declarations.

11 import { EventEmitter } from 'events';
                                ~~~~~~~~

node_modules/vite/dist/node/index.d.ts:12:25 - error TS2307: Cannot find module 'events' or its corresponding type declarations.

12 import * as events from 'events';
                           ~~~~~~~~

node_modules/vite/dist/node/index.d.ts:14:26 - error TS2307: Cannot find module 'fs' or its corresponding type declarations.

14 import type * as fs from 'fs';
                            ~~~~

node_modules/vite/dist/node/index.d.ts:16:23 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

16 import * as http from 'http';
                         ~~~~~~

node_modules/vite/dist/node/index.d.ts:17:38 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

17 import type { IncomingMessage } from 'http';
                                        ~~~~~~

node_modules/vite/dist/node/index.d.ts:22:27 - error TS2307: Cannot find module 'net' or its corresponding type declarations.

22 import type * as net from 'net';
                             ~~~~~

node_modules/vite/dist/node/index.d.ts:23:42 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

23 import type { OutgoingHttpHeaders } from 'http';
                                            ~~~~~~

node_modules/vite/dist/node/index.d.ts:36:43 - error TS2307: Cannot find module 'tls' or its corresponding type declarations.

36 import type { SecureContextOptions } from 'tls';
                                             ~~~~~

node_modules/vite/dist/node/index.d.ts:37:29 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

37 import type { Server } from 'http';
                               ~~~~~~

node_modules/vite/dist/node/index.d.ts:38:41 - error TS2307: Cannot find module 'https' or its corresponding type declarations.

38 import type { Server as Server_2 } from 'https';
                                           ~~~~~~~

node_modules/vite/dist/node/index.d.ts:39:41 - error TS2307: Cannot find module 'net' or its corresponding type declarations.

39 import type { Server as Server_3 } from 'net';
                                           ~~~~~

node_modules/vite/dist/node/index.d.ts:40:55 - error TS2307: Cannot find module 'https' or its corresponding type declarations.

40 import type { ServerOptions as ServerOptions_2 } from 'https';
                                                         ~~~~~~~

node_modules/vite/dist/node/index.d.ts:41:37 - error TS2307: Cannot find module 'http' or its corresponding type declarations.

41 import type { ServerResponse } from 'http';
                                       ~~~~~~

node_modules/vite/dist/node/index.d.ts:44:30 - error TS2307: Cannot find module 'stream' or its corresponding type declarations.

44 import type * as stream from 'stream';
                                ~~~~~~~~

node_modules/vite/dist/node/index.d.ts:48:27 - error TS2307: Cannot find module 'url' or its corresponding type declarations.

48 import type * as url from 'url';
                             ~~~~~

node_modules/vite/dist/node/index.d.ts:49:35 - error TS2307: Cannot find module 'url' or its corresponding type declarations.

49 import type { URL as URL_2 } from 'url';
                                     ~~~~~

node_modules/vite/dist/node/index.d.ts:51:34 - error TS2307: Cannot find module 'zlib' or its corresponding type declarations.

51 import type { ZlibOptions } from 'zlib';
                                    ~~~~~~

node_modules/vite/dist/node/index.d.ts:273:21 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

273     importedAssets: Set<string>;
                        ~~~

node_modules/vite/dist/node/index.d.ts:274:18 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

274     importedCss: Set<string>;
                     ~~~

node_modules/vite/dist/node/index.d.ts:377:37 - error TS2503: Cannot find namespace 'NodeJS'.

377     export interface Server extends NodeJS.EventEmitter {
                                        ~~~~~~

node_modules/vite/dist/node/index.d.ts:808:15 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

808         pfx?: Buffer | string
                  ~~~~~~

node_modules/vite/dist/node/index.d.ts:1154:21 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1154     urlToModuleMap: Map<string, ModuleNode>;
                         ~~~

node_modules/vite/dist/node/index.d.ts:1155:20 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1155     idToModuleMap: Map<string, ModuleNode>;
                        ~~~

node_modules/vite/dist/node/index.d.ts:1156:23 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1156     fileToModulesMap: Map<string, Set<ModuleNode>>;
                           ~~~

node_modules/vite/dist/node/index.d.ts:1156:35 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1156     fileToModulesMap: Map<string, Set<ModuleNode>>;
                                       ~~~

node_modules/vite/dist/node/index.d.ts:1157:22 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1157     safeModulesPath: Set<string>;
                          ~~~

node_modules/vite/dist/node/index.d.ts:1161:37 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1161     getModulesByFile(file: string): Set<ModuleNode> | undefined;
                                         ~~~

node_modules/vite/dist/node/index.d.ts:1163:46 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1163     invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number): void;
                                                  ~~~

node_modules/vite/dist/node/index.d.ts:1170:56 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1170     updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean, ssr?: boolean): Promise<Set<ModuleNode> | undefined>;
                                                            ~~~

node_modules/vite/dist/node/index.d.ts:1170:99 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1170     updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean, ssr?: boolean): Promise<Set<ModuleNode> | undefined>;
                                                                                                       ~~~

node_modules/vite/dist/node/index.d.ts:1170:175 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1170     updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean, ssr?: boolean): Promise<Set<ModuleNode> | undefined>;
                                                                                                                                                                                   ~~~

node_modules/vite/dist/node/index.d.ts:1189:16 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1189     importers: Set<ModuleNode>;
                    ~~~

node_modules/vite/dist/node/index.d.ts:1190:22 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1190     importedModules: Set<ModuleNode>;
                          ~~~

node_modules/vite/dist/node/index.d.ts:1191:22 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1191     acceptedHmrDeps: Set<ModuleNode>;
                          ~~~

node_modules/vite/dist/node/index.d.ts:1229:36 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1229 export declare type PackageCache = Map<string, PackageData>;
                                        ~~~

node_modules/vite/dist/node/index.d.ts:1364:16 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1364         skip?: Set<Plugin>;
                    ~~~

node_modules/vite/dist/node/index.d.ts:1711:91 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

1711 export declare function send(req: IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, options: SendOptions): void;
                                                                                               ~~~~~~

node_modules/vite/dist/node/index.d.ts:1769:12 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

1769     cache: Map<string, boolean>;
                ~~~

node_modules/vite/dist/node/index.d.ts:2387:42 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2387     close(code?: number, data?: string | Buffer): void
                                              ~~~~~~

node_modules/vite/dist/node/index.d.ts:2457:55 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2457     listener: (this: WebSocket, code: number, reason: Buffer) => void
                                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2475:39 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2475     listener: (this: WebSocket, data: Buffer) => void
                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2492:55 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2492     listener: (this: WebSocket, code: number, reason: Buffer) => void
                                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2510:39 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2510     listener: (this: WebSocket, data: Buffer) => void
                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2527:55 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2527     listener: (this: WebSocket, code: number, reason: Buffer) => void
                                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2545:39 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2545     listener: (this: WebSocket, data: Buffer) => void
                                           ~~~~~~

node_modules/vite/dist/node/index.d.ts:2562:38 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2562     listener: (code: number, reason: Buffer) => void
                                          ~~~~~~

node_modules/vite/dist/node/index.d.ts:2574:58 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2574     addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
                                                              ~~~~~~

node_modules/vite/dist/node/index.d.ts:2583:38 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2583     listener: (code: number, reason: Buffer) => void
                                          ~~~~~~

node_modules/vite/dist/node/index.d.ts:2595:61 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2595     removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
                                                                 ~~~~~~

node_modules/vite/dist/node/index.d.ts:2610:27 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2610     export type RawData = Buffer | ArrayBuffer | Buffer[]
                               ~~~~~~

node_modules/vite/dist/node/index.d.ts:2610:50 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2610     export type RawData = Buffer | ArrayBuffer | Buffer[]
                                                      ~~~~~~

node_modules/vite/dist/node/index.d.ts:2615:33 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2615     export type Data = string | Buffer | ArrayBuffer | Buffer[]
                                     ~~~~~~

node_modules/vite/dist/node/index.d.ts:2615:56 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2615     export type Data = string | Buffer | ArrayBuffer | Buffer[]
                                                            ~~~~~~

node_modules/vite/dist/node/index.d.ts:2620:48 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2620     export type CertMeta = string | string[] | Buffer | Buffer[]
                                                    ~~~~~~

node_modules/vite/dist/node/index.d.ts:2620:57 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2620     export type CertMeta = string | string[] | Buffer | Buffer[]
                                                             ~~~~~~

node_modules/vite/dist/node/index.d.ts:2651:29 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2651         generateMask?(mask: Buffer): void
                                 ~~~~~~

node_modules/vite/dist/node/index.d.ts:2682:26 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2682             dictionary?: Buffer | Buffer[] | DataView | undefined
                              ~~~~~~

node_modules/vite/dist/node/index.d.ts:2682:35 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2682             dictionary?: Buffer | Buffer[] | DataView | undefined
                                       ~~~~~~

node_modules/vite/dist/node/index.d.ts:2731:20 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

2731         protocols: Set<string>,
                        ~~~

node_modules/vite/dist/node/index.d.ts:2753:18 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

2753         clients: Set<T>
                      ~~~

node_modules/vite/dist/node/index.d.ts:2762:22 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

2762         upgradeHead: Buffer,
                          ~~~~~~

node_modules/vite/dist/node/index.d.ts:2879:14 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

2879     clients: Set<WebSocketClient>;
                  ~~~

node_modules/vite/dist/node/index.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.

1 /// <reference types="node" />
                        ~~~~

node_modules/@types/prop-types/index.d.ts:20:41 - error TS2304: Cannot find name 'Iterable'.

20 export interface ReactNodeArray extends Iterable<ReactNodeLike> {}
                                           ~~~~~~~~

node_modules/@types/scheduler/tracing.d.ts:64:35 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

64   onWorkScheduled: (interactions: Set<Interaction>, threadID: number) => void;
                                     ~~~

node_modules/@types/scheduler/tracing.d.ts:70:34 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

70   onWorkCanceled: (interactions: Set<Interaction>, threadID: number) => void;
                                    ~~~

node_modules/@types/scheduler/tracing.d.ts:80:33 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

80   onWorkStarted: (interactions: Set<Interaction>, threadID: number) => void;
                                   ~~~

node_modules/@types/scheduler/tracing.d.ts:86:33 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

86   onWorkStopped: (interactions: Set<Interaction>, threadID: number) => void;
                                   ~~~

node_modules/@types/scheduler/tracing.d.ts:90:12 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

90   current: Set<Interaction>;
              ~~~

node_modules/@types/scheduler/tracing.d.ts:102:40 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

102 export function unstable_getCurrent(): Set<Interaction> | null;
                                           ~~~

node_modules/@types/react/index.d.ts:228:10 - error TS2456: Type alias 'ReactFragment' circularly references itself.

228     type ReactFragment = Iterable<ReactNode>;
             ~~~~~~~~~~~~~

node_modules/@types/react/index.d.ts:228:26 - error TS2304: Cannot find name 'Iterable'.

228     type ReactFragment = Iterable<ReactNode>;
                             ~~~~~~~~

node_modules/@types/react/index.d.ts:229:10 - error TS2456: Type alias 'ReactNode' circularly references itself.

229     type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;
             ~~~~~~~~~

node_modules/@types/react/index.d.ts:412:23 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.

412         interactions: Set<SchedulerInteraction>,
                          ~~~


Found 86 errors.

Validations

@FabianFrank
Copy link
Author

happy to make a PR with the fix if this is confirmed to be indeed removable

@haoqunjiang
Copy link
Member

It's because the project is missing the @types/node dependency.

@FabianFrank
Copy link
Author

FabianFrank commented Dec 16, 2022

It's because the project is missing the @types/node dependency.

Installing that dependency does also fix the build errors. However, the dependency is not in the template and nothing in the template seems to ever build what tsconfig.node.json describes (and actually if it would, out of the box it would fail). It still seems unused to me?

@dominikg
Copy link
Contributor

It's because the project is missing the @types/node dependency.

Installing that dependency does also fix the build errors. However, the dependency is not in the template and nothing in the template seems to ever build what tsconfig.node.json describes (and actually if it would, out of the box it would fail). It still seems unused to me?

vite.config.ts is bundled by vite with esbuild. so that config is used.

@FabianFrank
Copy link
Author

FabianFrank commented Dec 18, 2022

vite.config.ts is bundled by vite with esbuild. so that config is used.

It was my first assumption as well since tsconfig.node.json only includes vite.config.ts. However, you can delete tsconfig.node.json and both vite build and vite preview still work fine without errors. I also tried grep and GitHub search and no code anywhere seems to reference tsconfig.node.json (except tsconfig.json where again you can remove that reference and nothing breaks).

@C-Higgins
Copy link

C-Higgins commented Mar 18, 2023

vite.config.ts is bundled by vite with esbuild. so that config is used.

It was my first assumption as well since tsconfig.node.json only includes vite.config.ts. However, you can delete tsconfig.node.json and both vite build and vite preview still work fine without errors. I also tried grep and GitHub search and no code anywhere seems to reference tsconfig.node.json (except tsconfig.json where again you can remove that reference and nothing breaks).

I've been looking into this, and a lot about this starter project's config doesn't make much sense to me. According to the original issue #6324, importing something in vite.config.ts would pollute the global types such that the code in src could resolve node types.

  1. The type resolution rules already import all instances of @types/*, and a package depending on @types/node would add that package, so it should be the case that the node types are available in browser code even without importing anything, just by installing some package with that dependency. In my tests, that seems to be the case.

Then they said that they resolved the issue by splitting the ts configs via references.

  1. By referencing that file, you now include it with tsc -b where you otherwise would only be building the src folder. The build fails because it's trying to build the vite file; removing the reference passes because it ignores the vite file.
  2. The types being available are independent from importing anything. Splitting the configs like this doesn't have anything to do with what you installed into the package and thereby what types are available.

So I don't understand what was going on in that issue. The solution does not solve the problem. The only way a scheme like this could work is by specifying types: [] to disable automatic inclusion; this would make imports meaningful for type resolution. But unless you're willing to do that, I think you can safely remove this file and just deal with having node types polluting the browser code.

@silvenon
Copy link

silvenon commented Jan 10, 2024

I also used to think that there was more to tsconfig.node.json, like some clever recommendation, based on its name, but it seems to be a sort of a hack. Whatever it was considered to be doing before it doesn't seem to be achieving it anymore, browser global types are available in vite.config.ts.

I'm deleting it as well. Project References aren't intended for this purpose.

@FranciscoKloganB
Copy link

FranciscoKloganB commented Apr 30, 2024

Just shimming in a few months later. I personally think that TypeScript project references are confusing. Extends works fine and is in my opinion often easier to reason about. The problem is that vite.config.ts does not allow specifying what tsconfig should be used for dev/production, like rollup does. So unless I am mistaken, Vite kind of depends on a "include everything" approach.

@silvenon
Copy link

silvenon commented Apr 30, 2024

I'd also like to chime in because since my previous comment I learned an important trick in project references. I used to think that they have to emit something, but it turns out that we can use them to connect projects that don't emit, by creating a config with an empty includes or files:

{
  "includes": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ]
}
  • here tsconfig.app.json is the former tsconfig.json which includes src and doesn't emit, now I can delete references from that project
  • in tsconfig.node.json I can replace "composite": true with "noEmit": true, which previously wasn't allowed

Now running tsc --build will type check both projects and it will no longer compile vite.config.ts!

I read about the importance of separating type-checking environments, so I've come to appreciate the intent here, but I think the current implementation is wrong because running tsc doesn't report errors in vite.config.ts. tsc --build does, but it also compiles vite.config.ts, which is the implication of "composite": true.

It's a shame that project references are so heavily underdocumented.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants