eclipse-thingweb / node-wot

A fast and extensible framework to connect any device with your browser and backend applications
https://thingweb.io
Other
166 stars 80 forks source link

Webpack and node-wot Browser bundle #324

Open relu91 opened 4 years ago

relu91 commented 4 years ago

I am trying to use node-wot as a client in a webpack application. The library can be only loaded using a dynamic import (i.e. const wot = await import("@node-wot/browser-bundle")) and it seems that it misses some node built-ins. In fact, subscribing to an event throws the following error:

app.js:175 Uncaught (in promise) TypeError: _$punycode_37.toASCII is not a function
    at Url../node_modules/@node-wot/browser-bundle/dist/wot-bundle.min.js.Url.parse (app.js:175)
    at Object.urlParse [as parse] (app.js:175)
    at Function.e.extractScheme (app.js:175)
    at app.js:175
    at Array.map (<anonymous>)
    at Object.t.getClientFor (app.js:175)
    at app.js:175
    at new Promise (<anonymous>)
    at Object.t.subscribeEvent (app.js:175)
    at app.js:10052

AFIK The punycode library should be a builtin of node.js, but here it misses the toASCII function. However, if you require node-wot as an html script it works.

Does somebody have more experience with webpack and node-wot?

p.s. I also want to add that for the browser bundle we don't have a valid typescript type definition file.

danielpeintner commented 4 years ago

In fact, subscribing to an event throws the following error:

I did try to reproduce the issue by

exposing counter sample

node packages\cli\dist\cli.js examples\scripts\counter.js

loading HTML in one browser

.../thingweb.node-wot/examples/browser/counter.html?url=http://localhost:8080/counter

load the same HTML in another browser/tab

.../thingweb.node-wot/examples/browser/counter.html?url=http://localhost:8080/counter

subscribe to event "change" in one tab and increment in the other and both counts should be in sync. In my case this still works.

relu91 commented 4 years ago

yes, indeed.

However, if you require node-wot as an html script it works.

it only happens with webpack.

danielpeintner commented 4 years ago

Sorry I didn’t read it carefully enough...

Having said that, I wonder whether it make sense to have some kind of "manual tests". e.g. by creating a directory "/manual-tests" and having sub-directories like "issue-324" where we can put the test and a README how it can be tested or sample code.

Do you think you can provide such a manual test? Or do you/others think this is a stupid idea. I wouldn't mind ;-)