safe-global / safe-core-sdk

The Safe{Core} SDK allows builders to add account abstraction functionality into their apps.
https://docs.safe.global/sdk/overview
MIT License
252 stars 193 forks source link

Split the build into two: one for CommonJS modules and one for ESM #243

Open mmv08 opened 2 years ago

mmv08 commented 2 years ago

Context / issue

If you use NodeJS and ESModules, the library imports do not work as expected, you can see an example in this issue: https://ethereum.stackexchange.com/questions/133776/error-in-deploying-a-safe-methods-is-empty

It means that for ESM you have to do this:

import SafeCoreSDK from '@gnosis.pm/safe-core-sdk'

console.log(SafeCoreSDK)
// {
//  default: SafeCoreSDK
// }
const SDK = SafeCoreSDK.default

Proposed solution

Separate builds for esm and commonjs like other libraries do. An example - https://github.com/gnosis/evm-proxy-detection

Alternatives

Can't see any

Additional context

mmv08 commented 1 year ago

I've also just discovered that this completely breaks types with typescript

dasanra commented 1 year ago

Example on how to do this based on safe-apps-sdk https://github.com/safe-global/safe-apps-sdk/pull/512