RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
290 stars 46 forks source link

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

Closed pius closed 3 years ago

pius commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

@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:

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 commented 3 years ago

@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 commented 3 years ago

@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.