Skip to content

fix: esm-only compatibility support issue #9#10

Open
robertsoniv wants to merge 1 commit into
Sitecore:mainfrom
robertsoniv:fix/all/esm-only-support
Open

fix: esm-only compatibility support issue #9#10
robertsoniv wants to merge 1 commit into
Sitecore:mainfrom
robertsoniv:fix/all/esm-only-support

Conversation

@robertsoniv
Copy link
Copy Markdown

📌 Description

This PR addresses the ESM/CommonJS compatibility issue in Sitecore Cloud-SDK packages that prevents their use in modern JavaScript frameworks and ESM-only projects. The changes ensure all packages work seamlessly in both ESM and CommonJS environments while maintaining backward compatibility.

Key Changes:

  • Updated package.json exports: Implemented proper conditional exports syntax with import/require conditions for all packages
  • Added module type declaration: Added "type": "module" to all package.json files to properly declare ESM support
  • Fixed ESM wrapper files: Removed invalid 'use strict'; statements from ESM wrapper files
  • Enhanced TypeScript configuration: Ensured proper dual build outputs for both module systems
  • Maintained backward compatibility: All existing CommonJS usage patterns continue to work

Technical Implementation:

  • Modified exports field in package.json to use proper conditional export syntax
  • Updated ESM wrapper files (browser.js, server.js, internal.js) to remove CommonJS-specific code
  • Ensured cross-package dependencies work correctly in both module systems
  • Verified browser-specific imports function properly in ESM-only projects

This fix resolves module resolution errors like Cannot find module '@sitecore-cloudsdk/events/browser' that occur in projects with "type": "module" in package.json, enabling adoption in modern frameworks like TanStack Start, Vite, and Next.js App Router.

🔍 Related issues

Fixes #[9] - ESM/CommonJS Compatibility Issue - Packages Fail in ESM-Only Projects

📦Affected Packages

  • Utils
  • Core
  • Events
  • Personalize
  • Search
  • Examples/nextjs app
  • Github Workflows
  • Others

pbarrenechea
pbarrenechea previously approved these changes Oct 23, 2025
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.

3 participants