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

Polyfill node libraries within the sdk #645

Open
Blackglade opened this issue Sep 8, 2022 · 3 comments
Open

Polyfill node libraries within the sdk #645

Blackglade opened this issue Sep 8, 2022 · 3 comments
Labels
new-feature-request Feature request that needs triage Team Lamprey

Comments

@Blackglade
Copy link

Blackglade commented Sep 8, 2022

Problem

According to the FAQ page:

Webpack 5 no longer auto-polyfills some of the node modules used by this sdk. You will have to polyfill them to fix any errors regarding missing modules.

It seems that most sdk maintainers in the industry have opted for doing package level polyfills and automatically including checks to see crypto, buffer, and other relevant libraries are available instead of asking for the user to polyfill on their end.

It seems the direction that the Algorand SDK has chosen will cause more problems for its users not experienced with webpack or are simply looking for a hassle free way to start building with Algorand. I believe this is net detrimental to the developer experience.

Solution

Including all relevant polyfill libraries and do a sanity check to see if a native version exists given the execution environment instead of asking users to do polyfills.

@Blackglade Blackglade added the new-feature-request Feature request that needs triage label Sep 8, 2022
@SilentRhetoric
Copy link

Strongly support this recommendation. This polyfill issue has generated a ton of questions and frustrations in the dev community.

@jasonpaulos
Copy link
Contributor

jasonpaulos commented Sep 8, 2022

We do include polyfills for all necessary libraries in our browser build (currently this is just Buffer). See our README, which has a snippet of HTML that you can drop into any webpage and have the algosdk package available without any further configuration.

Problems tend to arise when using 3rd party frameworks to build for the browser, e.g. React or Vite, which have their own build processes we cannot control. We attempt to make it possible for these frameworks to identify and use our browser build (with its added polyfills), by declaring it in our package.json, but we cannot control if a framework decides to instead consume the code declared under "module" or "main" (which are meant for Node.js).

We unfortunately do not test with every browser framework and do not know their build processes. If you have suggestions for improvements we can make to better support a framework, please let us know, I think we'd be more than happy to make this process easier for everyone.

Note my reply to your other comment here about the crypto module, which is not an issue of a missing polyfill, but rather an issue of the React webpack build being overly cautious: #643 (comment)

@jasonpaulos
Copy link
Contributor

I've discovered a way of fixing the missing crypto module error without any additional configuration by users, and it's in #707.

I have some ideas about how to fix the Buffer issue as well, which I've described in #708.

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 Team Lamprey
Projects
None yet
Development

No branches or pull requests

5 participants
@winder @jasonpaulos @Blackglade @SilentRhetoric and others