Skip to content

fix(nodejs): Correct exports require mapping to use index.cjs#39

Merged
santhoshtr merged 1 commit intomasterfrom
fix-nodejs-exports-require-mapping
Jan 19, 2026
Merged

fix(nodejs): Correct exports require mapping to use index.cjs#39
santhoshtr merged 1 commit intomasterfrom
fix-nodejs-exports-require-mapping

Conversation

@santhoshtr
Copy link
Member

Summary

Fixes issue #36 - Node.js package.json has incorrect CommonJS require mapping.

Changes

  • Changed "require": "./index.node" to "require": "./index.cjs" in exports configuration
  • Enables proper platform detection for CommonJS users

Why This Matters

  • index.node is a native ELF binary without platform detection
  • index.cjs is the correct CommonJS wrapper that:
    • Detects platform (linux-x64, darwin-arm64, win32-x64, etc.)
    • Dynamically loads platform-specific binary
    • Provides helpful error messages for unsupported platforms

Impact

  • Before: require("sentencex") fails across platforms
  • After: Proper platform detection and error handling work as expected

Testing

  • Verified with CommonJS require scenarios
  • No breaking changes for ES module imports (already using correct index.mjs)

Fix package.json exports to use './index.cjs' instead of './index.node'
for CommonJS require() statements.

The native binary (index.node) should not be directly required as it
doesn't provide platform detection. The index.cjs wrapper properly:
- Detects platform and architecture
- Loads the correct platform-specific binary
- Provides helpful error messages for unsupported platforms

Fixes #36
@santhoshtr santhoshtr merged commit b956653 into master Jan 19, 2026
21 of 22 checks passed
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