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

bundle.run links and web browser example in the README are broken #50

Closed
pius opened this issue Apr 19, 2020 · 8 comments
Closed

bundle.run links and web browser example in the README are broken #50

pius opened this issue Apr 19, 2020 · 8 comments

Comments

@pius
Copy link

pius commented Apr 19, 2020

The README gives the following example for getting started with Dat in the browser:

<script src="https://bundle.run/dat-sdk@1"></script>
<script src="https://bundle.run/dat-sdk@1/promise.js"></script>
<script src="https://bundle.run/dat-sdk@1/auto.js"></script>
<script>
  const SDK = window.datSDK
  // Look at the examples from here
</script>

Unfortunately those script links are broken. Are there updated sources or an updated "Hello World" browser example you would recommend?

@RangerMauve
Copy link
Owner

Hey, what sort of breaking are you seeing? Are you getting a 404 or an error of some kind?

It usually takes a while to load the first time you run it.

@hamnox
Copy link

hamnox commented Apr 29, 2020

Am also having this problem. I think it was a timeout error for the bundle? I deleted my setup after the umpteenth attempt to get dat to load.

@RangerMauve
Copy link
Owner

I suggest trying to build the bundle from source locally on your machine if you can. 😅 I guess bundle.run was the wrong choice to advertise in the docs after all.

@mkroehnert
Copy link
Contributor

@RangerMauve first of all, thanks for providing this SDK.

However, I am also not able to use the SDK on a browser page as described here: https://github.com/datproject/sdk#building-a-bundle-for-browsers
I built it locally from the latest commit 16f52ee.

When I add the script tag for loading the created hyper-sdk-bundle.js to an index.html I get the following error in Firefox:

Uncaught SyntaxError: expected '=>' on the same line after an argument list, got '('      localhost:12345:19:10

The error on Chromium looks like this:

Uncaught SyntaxError: Unexpected identifier       localhost/:19

The content of the created bundle file from line 8 to line 19 looks like this:

...
module.exports = ({
  dnsProxy = DEFAULT_DNS_PROXY
} = {}) => {
  let cache = {};
  return {
    async resolveName(url, opts, cb) {
      if (typeof opts === 'function') {
        cb = opts;
        opts = {};
      }

      if (!cb) cb = noop;
...

@RangerMauve
Copy link
Owner

Hmm, I'm sadly overbooked with other things right now so I'm not sure what could be causing it. Does running the standard CLI on the dns-web file yield anything interesting?

Also, what version of Firefox was this running in and does it run when in other browser?

@mkroehnert
Copy link
Contributor

@RangerMauve no worries, this is not a high priority topic for me.

Those were the two browser versions I used for testing on Linux and it didn't work in either of them:

  • Mozilla Firefox 84.0.2
  • Chromium 87.0.4280.88

I ran npx standard dns-web.js but id did not yield anything.
npx standard hyper-sdk-bundle.js yielded a lot of output but nothing that looked problematic at first glance (I attached the full log here, if it is of interest: https://gist.github.com/mkroehnert/73a6c4eb9ca8fe310d5cd36f069cfca4).

If you have any other pointers on how this can be debugged, I could give it a try.
Is it possibly an error that has to do with the module syntax?

@mkroehnert
Copy link
Contributor

@RangerMauve please ignore my report above. It wasn't actually an issue with the hyper SDK, but in the index.htmlthat was loading it.

Since await can only be called in an async context, I wrapped const sdk = await SDK(...) in an async function but initially used the wrong syntax.
However, I had to replace window.datSDK with window.hyperSDK, for which I created a PR.

In the end, this is what worked for me:

  <script src="hyper-sdk-bundle-3.0.3.js"></script>
  <script>
    const SDK = window.hyperSDK
    async function run() {
     const sdk = await SDK({persist: false})
    }
    run()
  </script>

@RangerMauve
Copy link
Owner

@mkroehnert Awesome, that's good to hear.

I'm gonna close this issue for now since it looks like stuff is working in the browser again.

If anyone is having trouble, feel free to comment and we'll re-open.

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

4 participants