You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using current node engines with esm modules is difficult and require some hacks as we are compiling safe-core-sdk using commonjs
With esm, import and export declarations are determined statically at compile time. This static structure allows for better tooling with things like tree shaking (dead code elimination), faster lookup, and advanced optimizations.
Consequences of supporting only commonjs
In Browsers: Browser based applications that want to use out SDK will need to transpile the code, which adds an additional step to their build process
Compatibility: Modern libraries and applications that prefer or require esm modules might face difficulties integrating with our SDK
Tree Shaking: esm enables effective tree shaking, which is important for reducing the final bundle size in frontend applications. commonjs does not support tree shaking efficiently.
By offering both formats, we can ensure wider compatibility and make the SDK more attractive to a broader range of developers and projects.
Proposed solution
The proposed solution would compile safe-core-sdk with a dual output with both commonjs and esm modules being distributed inside the package
And it depends on how we're running it, so it could be our configuration. If I run the code with ts-node or Next.js, the issue does not happen. If I use esbuild or tsx, then it is nested inside an extra default prop
yagopv
changed the title
feat: ESM Modules
[SDK Refactor] ESM Modules
Jun 17, 2024
yagopv
changed the title
[SDK Refactor] ESM Modules
[SDK Refactoring] ESM Modules
Jun 17, 2024
Context / issue
Using current node engines with esm modules is difficult and require some hacks as we are compiling
safe-core-sdk
using commonjsWith
esm
, import and export declarations are determined statically at compile time. This static structure allows for better tooling with things like tree shaking (dead code elimination), faster lookup, and advanced optimizations.Consequences of supporting only
commonjs
esm
modules might face difficulties integrating with our SDKesm
enables effective tree shaking, which is important for reducing the final bundle size in frontend applications.commonjs
does not support tree shaking efficiently.By offering both formats, we can ensure wider compatibility and make the SDK more attractive to a broader range of developers and projects.
Proposed solution
The proposed solution would compile
safe-core-sdk
with a dual output with both commonjs and esm modules being distributed inside the packageAdditional context
First issue
Similar solution in safe-apps-sdk
Issue with Safe.create
The text was updated successfully, but these errors were encountered: