#3413

@types/node collides with scriptc-node-fallback.d.ts in projects without tsconfig.json

Openespetroopened 4d ago

Summary

In a project with no tsconfig.json, installing @types/node alongside a dependency whose .d.ts contains /// <reference types="node" /> makes scriptc build fail with ~237 duplicate-identifier errors between node_modules/@types/node/*.d.ts and the bundled ambient/scriptc-node-fallback.d.ts (e.g. Duplicate identifier 'BufferEncoding', Duplicate identifier 'assert', Cannot redeclare block-scoped variable 'performance').

  • Adding any tsconfig.json → builds fine.
  • No @types/node installed → builds fine.

Cause

packages/compiler/src/frontend/program.ts (~line 1013): const nodeTypes = config.configFile ? resolveNodeTypes7(entryPath) : null; — the project's @types/node is only resolved when a tsconfig exists. Without one, nodeTypes === null → fallbackDtsPath() joins coreRoots, while @types/node is also pulled in by the dep's type-reference directive → both declaration sets load.

Reproduction

mkdir repro && cd repro && npm init -y && npm i -D @types/node
npm i clipanion@4.0.0-rc.4   # dep d.ts has /// <reference types="node" />
import { Cli } from "clipanion";
new Cli({});

(no tsconfig.json) → scriptc build → ~237 errors. Adding tsconfig.json → compiles.

Verified on main (d4c82a5c3), darwin-arm64. A PR is underway.

Activity

0

No activity yet.