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

Native ESM #819

Closed
PhearZero opened this issue Aug 28, 2023 · 3 comments
Closed

Native ESM #819

PhearZero opened this issue Aug 28, 2023 · 3 comments
Assignees
Labels
new-feature-request Feature request that needs triage

Comments

@PhearZero
Copy link
Contributor

❌ Problem

The following errors due to node.js resolving the commonjs bundle while using native esm modules.

Reproduction: https://github.com/PhearZero/js-algorand-sdk-node-18-module/tree/main

import { Indexer } from 'algosdk'

🤔Reasoning:

While modern bundlers have robust resolvers, it would be good to have first class support for esm without third party tools. This will also improve third party bundlers ability to tree shake.

✅ Solution

Convert package to esm.

📦Dependencies

This requires moving to tsx and slight refactoring of the codebase.

‼️ Urgency

Very low priority

@PhearZero PhearZero added the new-feature-request Feature request that needs triage label Aug 28, 2023
PhearZero added a commit to PhearZero/js-algorand-sdk that referenced this issue Aug 28, 2023
@PhearZero PhearZero mentioned this issue Aug 28, 2023
2 tasks
@jasonpaulos
Copy link
Contributor

Hi @PhearZero, I am under the impression that having this line in our package.json is enough to provide ESM support:

"module": "dist/esm/index.js",

Can you please share more details about your environment (e.g. operating system, node version) and the exact error you're receiving?

@jasonpaulos jasonpaulos self-assigned this Aug 29, 2023
@PhearZero
Copy link
Contributor Author

PhearZero commented Aug 29, 2023

Hello @jasonpaulos !

Hi @PhearZero, I am under the impression that having this line in our package.json is enough to provide ESM support:

This is true for most bundlers but it's actually not standardized, just a widely adopted key. The actual package.json standard does not include module but exports. The previous ESM bundles where an attempt at "future proofing" but not compliant with the current specification.

Can you please share more details about your environment (e.g. operating system, node version) and the exact error you're receiving?

Should be any node/os combination that supports esm. Node >= v16

Here is the reproduction repo using Node v18: https://github.com/PhearZero/js-algorand-sdk-node-18-module

Steps:

npm init
npm install algosdk

Set package.json type to module

{
 "type": "module"
}

Import module

import {Indexer} from 'algosdk'

// Error does not provide named export since it's using the cjs bundle

@jasonpaulos
Copy link
Contributor

Addressed in #836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature-request Feature request that needs triage
Projects
None yet
Development

No branches or pull requests

2 participants