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

'import' and 'export' may appear only with 'sourceType: module' #15

Open
KyleMaas opened this issue Jan 26, 2021 · 17 comments
Open

'import' and 'export' may appear only with 'sourceType: module' #15

KyleMaas opened this issue Jan 26, 2021 · 17 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@KyleMaas
Copy link

Getting an error trying to build this:

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (587:0) while parsing (development path)/multiserver-dht/node_modules/reconnecting-websocket/dist/reconnecting-websocket-mjs.js
@KyleMaas
Copy link
Author

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.

@KyleMaas
Copy link
Author

Reported upstream here:

pladaria/reconnecting-websocket#149

@RangerMauve RangerMauve added bug Something isn't working help wanted Extra attention is needed labels Jan 30, 2021
@RangerMauve
Copy link
Owner

Thanks for the report! This sounds like an upstream thing. 😅 I'll subscribe to it and update the deps when it's fixed.

@RangerMauve
Copy link
Owner

What are you using to build the project by the way?

@KyleMaas
Copy link
Author

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

@tinchoz49
Copy link
Contributor

tinchoz49 commented Feb 2, 2021

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;"

@KyleMaas
Copy link
Author

KyleMaas commented Feb 2, 2021

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

@tinchoz49
Copy link
Contributor

Ah thanks for the catch up, I will take a look in that project.

@KyleMaas
Copy link
Author

KyleMaas commented Feb 2, 2021

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.

@KyleMaas
Copy link
Author

KyleMaas commented Feb 2, 2021

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.

@tinchoz49
Copy link
Contributor

I'm getting this error during the: npm install

Command failed: git checkout port-to-hyperswarm

@KyleMaas
Copy link
Author

KyleMaas commented Feb 2, 2021

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.

@tinchoz49
Copy link
Contributor

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.

@RangerMauve
Copy link
Owner

Has this been resolved?

@KyleMaas
Copy link
Author

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.

@KyleMaas
Copy link
Author

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

@KyleMaas
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants