Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update library exports to support both CommonJS and ES6 modules #225

Open
adriacidre opened this issue Mar 24, 2023 · 0 comments
Open

Update library exports to support both CommonJS and ES6 modules #225

adriacidre opened this issue Mar 24, 2023 · 0 comments

Comments

@adriacidre
Copy link
Contributor

We've encountered an issue when trying to use the self-sdk library with ES6 module syntax (import). The library works well with CommonJS syntax (require), but it throws an error when using import:

TypeError: Cannot read properties of undefined (reading 'build')
To improve the library's compatibility with various JavaScript environments, it would be great if the exports could be updated to support both CommonJS and ES6 modules.

Here's a suggestion for updating the exports in the library:

// Assuming you have something like this in your library
const SelfSDK = {
  build: () => {
    // Your logic here
  },
};

// Add the following lines
export default SelfSDK; // ES6 default export
module.exports = SelfSDK; // CommonJS export

Additionally, please ensure that the TypeScript configuration file (tsconfig.json) includes the following compiler options:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

These options allow TypeScript to generate code that can interoperate between CommonJS and ES6 modules.

By making these changes, users will be able to use both const SelfSDK = require("self-sdk"); and import SelfSDK from 'self-sdk'; without issues.

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

No branches or pull requests

1 participant