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

Fix jsDelivr deployment for use in browsers #468

Closed
leighmcculloch opened this issue Dec 20, 2019 · 1 comment
Closed

Fix jsDelivr deployment for use in browsers #468

leighmcculloch opened this issue Dec 20, 2019 · 1 comment
Labels

Comments

@leighmcculloch
Copy link
Member

Describe the bug
When importing stellar-sdk in HTML using the instructions that were previously visible in the README before change #487 took place, errors show in the console. Doing the same with CDNJS hosted version works fine, so something seems to be broken about our deployment on jsDelivr.

What version are you on?
I was attempting to use the latest version with jsDelivr. The same happens when setting the version to 3.3.0 which is the latest version right now.

To Reproduce

<!DOCTYPE html>
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.min.js"></script>
<script>
const horizon = new StellarSdk.Server("https://horizon-testnet.stellar.org", {});
console.log(horizon);
</script>
</body>
</html>

These are the console errors:

index.js:2 Uncaught ReferenceError: exports is not defined
    at index.js:2
index.html:9 Uncaught ReferenceError: StellarSdk is not defined
    at index.html:9

Expected behavior
The stellar-sdk could be included in a HTML page and StellarSdk could be accessed. This is how it works with the CDNJS deployment which works fine:

<!DOCTYPE html>
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/3.0.1/stellar-sdk.js"></script>
<script>
const horizon = new StellarSdk.Server("https://horizon-testnet.stellar.org", {});
console.log(horizon);
</script>
</body>
</html>

Additional context
Because this is an issue I opened #487 and removed the jsDelivr example from the README so we aren't recommending that in a highly visible place and causing people to trip up. It would still be great to fix this since jsDelivr is a popular CDN host.

@abuiles
Copy link
Contributor

abuiles commented Nov 18, 2020

@leighmcculloch I was just looking into this and the problem is that you are trying to load the node js version. It seems like cdnjs does some kind of transpiling before serving the file.

The good news is that we also include the Browser version as part of the release, you need to reference dist/ instead -- the following works:

<!DOCTYPE html>
<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/stellar-sdk.js"></script>
    <script>
      const horizon = new StellarSdk.Server("https://horizon-testnet.stellar.org", {});
      console.log(horizon);
    </script>
  </body>
</html>

@abuiles abuiles closed this as completed Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants