Open KyleMaas opened 3 years ago
Removing this line from reconnecting-websocket's package.json fixes the problem:
"module": "./dist/reconnecting-websocket-mjs.js",
I think I might need to report this upstream. I'll note that building hyperswarm-web by itself works regardless, and I can run test.js. It's when I try to integrate it into a larger project that this comes up.
Reported upstream here:
https://github.com/pladaria/reconnecting-websocket/issues/149
Thanks for the report! This sounds like an upstream thing. 😅 I'll subscribe to it and update the deps when it's fixed.
What are you using to build the project by the way?
@RangerMauve I can't say I'm great with Node stuff yet, and thankfully I wasn't the one who had to put together the build process. But, ultimately, this is the end of the chain:
https://github.com/KyleMaas/ssb-browser-demo/blob/add-dht-support-runnable/package.json
(That's a development branch for the new feature that would use this so people can test it out.)
That, several layers of dependencies deep, depends on this:
https://github.com/staltz/multiserver-dht/blob/master/package.json
We're still working on this whole process, but so far it's been quite promising. Right now we're using this as a workaround:
https://github.com/KyleMaas/ssb-browser-core/blob/add-dht-support-runnable/package.json#L49
Basically, it gets rid of the "module" line post-install, which makes everything hunky-dory. But ultimately it'd be much better if we didn't have to do that.
Hey @KyleMaas, how are you?
I think I might need to report this upstream. I'll note that building hyperswarm-web by itself works regardless, and I can run test.js. It's when I try to integrate it into a larger project that this comes up.
Since building the module isolated works ok, could be possible that there is a missing configuration somewhere on top.
reconnecting-websocket
is doing something valid by providing dist for mjs and cjs. a lot of modules are doing that these days and from the error it seems that some tool is trying to consume the mjs dist when it shouldn't.
I try to do a npm run build
of your branch by only building the ssb-dht-invite
and it works:
"postinstall": "pushd node_modules/ssb-dht-invite; npm install; npm run compile;"
@tinchoz49 As far as I can tell, the problem seems to come in when built using browserify, which is what ssb-browser-demo (the package at the end of the chain) uses. Each step up the chain seemed to build fine until I tried building ssb-browser-demo, so I have to assume it's somewhere in that step.
Past that, unfortunately, I can try to help find information if given direction, but I just don't really have the skills to debug it myself. I'm an old-school JavaScript guy who shunned JQuery for years for being an unnecessary dependency when raw DOM was perfectly adequate. And even then, it's been years since I've done much with JavaScript at all. So being thrust into the world of npm is exceedingly unfamiliar territory for me. More than happy to help, but my skill level with the build tools is very low.
Ah thanks for the catch up, I will take a look in that project.
If you want to try it, you'll need to try this branch:
https://github.com/KyleMaas/ssb-browser-demo/tree/add-dht-support-runnable
...which uses this branch of ssb-browser-core with this line of workaround postinstall script:
https://github.com/KyleMaas/ssb-browser-core/blob/add-dht-support-runnable/package.json#L49
Try it without the "sed" commands to see the error pop up.
I'll note that the rest of that postinstall script is still needed, because ssb-dht-invite still has to be compiled from TypeScript - the package doesn't seem to contain the compiled version.
I'm getting this error during the: npm install
Command failed: git checkout port-to-hyperswarm
Ah, sorry. Old version of a dependency was pinned in npm-shrinkwrap. Just pushed a new commit that should fix that. Please give it another try.
That works thanks.
I try npm run build
and it works.
Before that I build ssb-browser-core without the postinstall workaround for reconnecting-websocket.
Has this been resolved?
Unfortunately, it does not appear fixed. The error does not show up when ssb-browser-core is built by itself. Only when it is built into ssb-browser-demo.
I've made a branch to try to demonstrate it better:
https://github.com/KyleMaas/ssb-browser-demo/tree/add-dht-support-runnable-broken
I'm having some issues with sodium at the moment, which is throwing this off a bit for me. But this error still exists. Hopefully this branch will help duplicate it for you.
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (587:0) while parsing (base path)/ssb-browser-core/node_modules/ssb-dht-invite/node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js while parsing file: (base path)/ssb-browser-core/node_modules/ssb-dht-invite/node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js
at DestroyableTransform.end [as _flush] ((base path)/ssb-browser-demo/node_modules/insert-module-globals/index.js:114:21)
at DestroyableTransform.prefinish ((base path)/ssb-browser-demo/node_modules/readable-stream/lib/_stream_transform.js:138:10)
at DestroyableTransform.emit (node:events:378:20)
at prefinish ((base path)/ssb-browser-demo/node_modules/readable-stream/lib/_stream_writable.js:619:14)
at finishMaybe ((base path)/ssb-browser-demo/node_modules/readable-stream/lib/_stream_writable.js:627:5)
at endWritable ((base path)/ssb-browser-demo/node_modules/readable-stream/lib/_stream_writable.js:638:3)
at DestroyableTransform.Writable.end ((base path)/ssb-browser-demo/node_modules/readable-stream/lib/_stream_writable.js:594:41)
at PassThrough.onend (node:internal/streams/readable:689:10)
at Object.onceWrapper (node:events:484:28)
at PassThrough.emit (node:events:378:20)
Here is a copy of the error (base path removed).
We revisited DHT again and still had this problem. The way we worked around it is to patch reconnecting-websocket with a postinstall script, and that works now and is in mainline for ssb-browser-demo. So if you want to duplicate this, download mainline ssb-browser-demo, remove the postinstall script from package.json, and try building.
Getting an error trying to build this: