Skip to content

Import the roughjs root entry instead of roughjs/bin/* - #1

Open
mikeyzhong wants to merge 1 commit into
masterfrom
fix-native-esm-roughjs-import
Open

Import the roughjs root entry instead of roughjs/bin/*#1
mikeyzhong wants to merge 1 commit into
masterfrom
fix-native-esm-roughjs-import

Conversation

@mikeyzhong

Copy link
Copy Markdown
Owner

Problem

roughjs's bin/ files are ES modules with extensionless relative imports and no exports map, so any consumer loading this package in native Node ESM (no bundler) fails:

ERR_MODULE_NOT_FOUND: Cannot find module '.../roughjs/bin/core'
imported from .../roughjs/bin/svg.js

This surfaced in sketches PR 2116 review: import('sketches-dev') fails in plain Node because its dependency graph reaches this package's roughjs/bin/canvas / roughjs/bin/svg requires.

Fix

  • Renderer.tsx: import the root roughjs entry (resolves to the self-contained bundled builds, loadable everywhere) and use the rough.canvas() / rough.svg() factories — they return the same RoughCanvas / RoughSVG instances the constructors did. All remaining roughjs/bin/* imports in src are type-position only and erase at compile time.
  • Fold the previously hand-patched dist/components/ReactRough/ReactRough.d.ts props interface into ReactRough.tsx (and widen RoughProviderProps.children to ReactNode to match), so rebuilding dist no longer clobbers it.
  • Rebuilt dist/, bumped version to 1.0.3.

Verification

  • npm run build passes; both dist builds reference only roughjs (no bin/*).
  • Clean consumer project installing github:mikeyzhong/rough-react-wrapper#fix-native-esm-roughjs-import with "type": "module": import ReactRough, { Line, Path } from "rough-react-wrapper" loads in native Node.
  • Regenerated ReactRough.d.ts matches the old hand-patched public surface.

🤖 Generated with Claude Code

roughjs's bin/ files are ES modules with extensionless relative imports
and no exports map, so any consumer loading this package in native Node
ESM fails with ERR_MODULE_NOT_FOUND (roughjs/bin/svg.js -> './core').
The root roughjs entry resolves to the self-contained bundled builds,
which load everywhere; rough.canvas()/rough.svg() return the same
RoughCanvas/RoughSVG instances the constructors did.

Also fold the hand-patched dist/components/ReactRough/ReactRough.d.ts
props interface into the source (and widen RoughProviderProps.children
to ReactNode to match), so rebuilding dist no longer clobbers it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant