Skip to content

fix: make yarn build work cleanly (node-modules linker + TypeScript)#501

Merged
gre merged 2 commits into
masterfrom
fix/typescript-build-and-node-modules-linker
May 15, 2026
Merged

fix: make yarn build work cleanly (node-modules linker + TypeScript)#501
gre merged 2 commits into
masterfrom
fix/typescript-build-and-node-modules-linker

Conversation

@gre

@gre gre commented May 15, 2026

Copy link
Copy Markdown
Owner

Problem

yarn build was silently broken:

  • Babel compiled JS fine, but tsc -b --emitDeclarationOnly generated no .d.ts files
  • Root cause 1: Yarn PnP mode made tsc unable to resolve packages (react, @types/node, etc.)
  • Root cause 2: stale .tsbuildinfo files made tsc think the build was up-to-date even after rm -rf lib
  • Root cause 3: several pre-existing TypeScript errors blocked emission

This also caused the CI publish workflow to fail since gl@5.0.3 (pulled in as a transitive dep) doesn't compile on GCC 13 (Ubuntu 24.04).

Changes

  • .yarnrc.yml: switch to nodeLinker: node-modules so tsc resolves packages via normal node_modules lookup
  • package.json resolutions: force gl@9.0.0-rc.9 to avoid gl@5.0.3 (incompatible with GCC 13)
  • scripts/build.sh: delete *.tsbuildinfo on clean so tsc always regenerates .d.ts
  • babel.config.js: enable allowDeclareFields for @babel/preset-typescript
  • TypeScript fixes in gl-react, gl-react-dom, gl-react-headless, gl-react-expo:
    • declare modifier on context class fields (TS2612)
    • as unknown as double-cast for getContext.ts (TS2352)
    • (rest as any)[k] for readonly index signature delete (TS2542)
    • as "webgl" | "webgl2" | "auto" cast (TS2345)
  • packages/gl-react-expo/src/globals.d.ts and gl-react-native/src/globals.d.ts: minimal stubs for react-native, __DEV__, and global (RN peer deps not installed in dev)
  • packages/gl-react/tsconfig.json: add ../../node_modules/@types to typeRoots so @types/node is found

Verification

yarn build  # exits 0, all 5 packages compile with Babel + 27 .d.ts files generated

🤖 Generated with Claude Code

…ixes)

- Switch to nodeLinker: node-modules so tsc can resolve packages properly
- Force gl@9.0.0-rc.9 in resolutions to avoid gl@5.0.3 (fails to compile on GCC 13)
- Enable allowDeclareFields in babel preset-typescript
- Use declare modifier on context class fields (Bus, Node, connectSize)
- Fix as unknown as casts in getContext.ts (TS2352)
- Fix readonly index signature delete in GLViewDOM and gl-react-headless (TS2542)
- Fix version string cast in GLViewDOM (TS2345)
- Add globals.d.ts stubs for react-native/__DEV__/global in expo/native packages
- Fix build.sh to delete .tsbuildinfo on clean so tsc always regenerates .d.ts
- Extend typeRoots in gl-react tsconfig to include @types/node

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 15, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR restores a clean yarn build for the monorepo by switching Yarn to a node-modules linker and addressing TypeScript/Babel configuration issues that prevented tsc -b --emitDeclarationOnly from emitting .d.ts outputs.

Changes:

  • Switch Yarn to nodeLinker: node-modules and pin gl via root resolutions to avoid incompatible native builds.
  • Make the build script reliably rebuild TS declaration output by removing stale *.tsbuildinfo.
  • Fix/patch TypeScript compilation issues across packages (class context fields, delete on readonly rest props, WebGL context typing workarounds, minimal RN globals stubs, Babel TS preset config).

Reviewed changes

Copilot reviewed 13 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
.yarnrc.yml Switches Yarn to node-modules linker to restore standard module resolution for tsc.
package.json Pins gl via resolutions to avoid incompatible transitive builds on newer CI toolchains.
yarn.lock Updates lockfile to reflect the linker/resolution changes (notably the gl bump and related dependency graph shifts).
scripts/build.sh Cleans lib and *.tsbuildinfo per package before running Babel + tsc -b --emitDeclarationOnly.
babel.config.js Enables allowDeclareFields to support TS declare class fields under Babel.
packages/gl-react/tsconfig.json Expands typeRoots so @types/* (notably @types/node) are discoverable during composite builds.
packages/gl-react/src/Node.tsx Uses declare context to satisfy TS class field/context typing without emitting runtime fields.
packages/gl-react/src/connectSize.tsx Uses declare context for TS correctness with contextType.
packages/gl-react/src/Bus.tsx Uses declare context for TS correctness with contextType.
packages/gl-react-dom/src/GLViewDOM.tsx Adjusts deletion of rest props for TS and casts version for getContext call.
packages/gl-react-dom/src/getContext.ts Uses unknown double-casts to coerce getContext return types under current typings.
packages/gl-react-headless/src/index.tsx Uses (rest as any)[k] deletion to satisfy TS constraints on rest props.
packages/gl-react-expo/src/GLViewNative.tsx Adds a JSX spread cast to any to bypass TypeScript prop typing issues for expo-gl’s GLView.
packages/gl-react-expo/src/globals.d.ts Adds minimal ambient stubs for react-native, __DEV__, and global to typecheck without RN deps installed.
packages/gl-react-native/src/globals.d.ts Adds minimal ambient stubs for react-native and global to typecheck without RN deps installed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 57 to 60
<EXGLView
{...({} as any)}
style={[
style,
Comment on lines 176 to +180
this.canvas!,
debug
? { ...webglContextAttributes, preserveDrawingBuffer: true }
: webglContextAttributes,
version || "auto"
(version || "auto") as "webgl" | "webgl2" | "auto"
Comment on lines 6 to 9
let gl: WebGLRenderingContext | null = null;
if (version === "webgl2" || version === "auto") {
gl = canvas.getContext("webgl2", opts) as WebGLRenderingContext | null;
gl = canvas.getContext("webgl2", opts) as unknown as WebGLRenderingContext | null;
}
@gre gre merged commit ecb76b2 into master May 15, 2026
3 checks passed
@gre gre deleted the fix/typescript-build-and-node-modules-linker branch June 24, 2026 11:44
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