Skip to content

finding(components): the browser process shim in global.d.ts hides node's process from the package's own test project #6809

Description

@claude

Found while implementing objectui#6779 (PR #6808), out of that card's scope and filed rather than fixed.

What

packages/components/src/global.d.ts declares a browser shim for the process global:

// Global process for browser environmentsdeclareconstprocess: {env: {NODE_ENV: string;};};

packages/components/tsconfig.test.json sets "types": ["node", "@testing-library/jest-dom"], so @types/node IS in the test project. But the ambient declare const process above wins over the node global, and — because @types/node spells its module as export = process — it also becomes what import process from 'node:process' resolves to.

Measured, three spellings, same package

Trying to read the repo root in a test under packages/components/src/:

spellingresult
process.cwd()error TS2339: Property 'cwd' does not exist on type '{ env: { NODE_ENV: string; }; }'
import process from 'node:process' then process.cwd()same TS2339
import nodeProcess from 'node:process' then nodeProcess.cwd()same TS2339

Runtime is plain node in every case and all three work; only the declaration is wrong. The workaround PR #6808 used, with the reasoning written out at the call site:

(globalThisasunknownas{process: {cwd(): string}}).process.cwd()

Why it is worth recording

The failure mode is a confusing, self-contradicting diagnostic: types: ["node"] is configured, the import resolves, and the compiler still says the property is missing. The obvious next moves — importing the module, renaming the binding — both fail identically, so the cost is a real detour each time. It is also asymmetric with the rest of the repo: packages/i18n tests read their ratchet baselines with the plain join(process.cwd(), 'scripts/...') idiom, which simply does not compile in packages/components.

Not urgent: nothing is broken at runtime, and the workaround is local and documented.

Possible directions (not a recommendation — this needs a look, not a guess)

  • Narrow the shim to src only, so the test project keeps the real node global. The shim exists for browser builds; the test project is not one.
  • Or move it inside a declare global block scoped so it augments rather than replaces NodeJS.Process.
  • Or leave it and add a one-line comment at the declaration pointing at this issue, so the next person loses minutes instead of a detour.

Whoever picks this up should check whether the shim is still load-bearing at all — tsconfig.json already excludes tests, so the shim's audience is the package source.


Generated by Claude Code

Metadata

Metadata

Assignees

Labels

domain:uiobjectui ui stream: fix lands on the published library or apps — objectui execution seatpriority:p2

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions