Skip to content

fix(create-rstack): drop node types from lib template src - #379

Merged
chenjiahan merged 3 commits into
mainfrom
lib-src-drop-node-types
Aug 19, 2026
Merged

fix(create-rstack): drop node types from lib template src#379
chenjiahan merged 3 commits into
mainfrom
lib-src-drop-node-types

Conversation

@elecmonkey

@elecmonkey elecmonkey commented Aug 19, 2026

Copy link
Copy Markdown
Member

With node in types, setTimeout in src is typed NodeJS.Timeout and leaks into the published .d.ts, forcing consumers to install @types/node; web app and component lib's src is browser code and needs nothing from it, so node stays only in the tests config.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploying rstack-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9f710e9
Status: ✅  Deploy successful!
Preview URL: https://c8801506.rstack-cli.pages.dev
Branch Preview URL: https://lib-src-drop-node-types.rstack-cli.pages.dev

View logs

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node types were added intentionally.

They allow app code to use process.env.NODE_ENV and process.env.PUBLIC_*, which Rsbuild replaces at build time. It also support process.env.* or Node globals or APIs in rstack.config.*.

@elecmonkey

Copy link
Copy Markdown
Member Author

Node types were added intentionally.

They allow app code to use process.env.NODE_ENV and process.env.PUBLIC_*, which Rsbuild replaces at build time. It also support process.env.* or Node globals or APIs in rstack.config.*.

  1. The process.env could comes from Rspack. rstack/types references @rsbuild/core/types, which references @rspack/core/module, and that file declares:
namespace Rspack { interface Process { env: { [key: string]: any } } }
declare var process: NodeJS.Process;

With types: ["rstack/types"] and no node, process.env.NODE_ENV, process.env.PUBLIC_* and import.meta.env.* all still type-check.

  1. For app templates, I agree with you keeping node is the better default.

  2. For library templates it is not. Libraries emit .d.ts, and that is where @types/node leaks: setTimeout in src is typed NodeJS.Timeout instead of number. Rslib also does not deal any process.env.*: https://v1.rslib.rs/guide/advanced/env-vars#default-environment-variables.

@elecmonkey
elecmonkey requested a review from chenjiahan August 19, 2026 08:44
@chenjiahan chenjiahan changed the title fix(create-rstack): drop node types from template src fix(create-rstack): drop node types from lib template src Aug 19, 2026
@chenjiahan
chenjiahan merged commit fd6d11f into main Aug 19, 2026
5 checks passed
@chenjiahan
chenjiahan deleted the lib-src-drop-node-types branch August 19, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants