RangerMauve / dat-archive-web

DatArchive implementation for browsers that uses dat-gateway
MIT License
30 stars 4 forks source link

TypeError: fs.watch is not a function #11

Closed siuying closed 5 years ago

siuying commented 5 years ago

When I try to create a html based on example in README:

<html>
    <head>
        <script src="//unpkg.com/dat-archive-web/bundle.js"></script>
    </head>
    <body>
        <script>
            // After including the bundle in a script tag, or requiring it
            const archive = new DatArchive('dat://87ed2e3b160f261a032af03921a3bd09227d0a4cde73466c17114816cae43336')

            // Subscribe to network events
            archive.addEventListener("download", ({bytes}) => console.log(`Downloaded ${bytes} bytes`))

            // Subscribe to file events
            const emitter = archive.watch("/path/to/watch")
            emitter.addEventListener("change", ({path}) => console.log(`file at path: ${path} changed!`))

            archive.readFile('/index.html')
            .then((html) => console.log(html))
        </script>
    </body>
</html>

The page throw error: TypeError: fs.watch is not a function. I've tried this on Firefox and Chrome, both return same error.

RangerMauve commented 5 years ago

Would you mind posting a stack trace? Ideally fs shouldn't be getting used at all. :P

RangerMauve commented 5 years ago

Oh dang. It looks to be a race condition since the archive isn't fully 'loaded' yet.

Try using this code for loading the archive for now

const archive = await DatArchive.load('dat://whatever')
RangerMauve commented 5 years ago

Thank you for reporting this!

This should be fixed in Version 2.0.5 😁

siuying commented 5 years ago

Thanks a lot!

siuying commented 5 years ago

Now I get an error "Error: File not found" at bundle.js:5305:5

RangerMauve commented 5 years ago

Weird. You might want to add a short delay before trying to read anything from the archive so that the metadata can download.

RangerMauve commented 5 years ago

Else I'd check if the data ever gets loaded and that the archive is pinned somewhere.

siuying commented 5 years ago

Thanks. I suspects the given example have no peers. I tried to shared something on Beaker but I still get same errors. Would you have any feeds that is working from your side?

RangerMauve commented 5 years ago

Yeah, sadly the browser version is still having trouble loading archives that are just in home networks, I find that opening an archive in https://gateway.mauve.moe/ can help and also pinning archives to hashbase or a dat-store instance on a server.