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

worker_threads dependency breaks on Node 10 #47

Open
christianbundy opened this issue Sep 22, 2020 · 5 comments
Open

worker_threads dependency breaks on Node 10 #47

christianbundy opened this issue Sep 22, 2020 · 5 comments

Comments

@christianbundy
Copy link
Contributor

https://nodejs.org/docs/latest-v10.x/api/worker_threads.html#worker_threads_worker_threads

We need to run Node with an extra experimental flag for this. Are there any good alternatives to keep Node 10 compat?

See-also: ssbc/chloride#21

@emilbayes
Copy link
Member

All that is required is some way of detaching the buffer

@christianbundy
Copy link
Contributor Author

Right, but are there ways to detach the buffer cleanly without any postMessage() API?

@emilbayes
Copy link
Member

MesaageChannels was the only way I could find, but I didn’t consider node 10 at the time

@mafintosh
Copy link
Member

@emilbayes could just make it a noop if that dep doesn't exist

@glowkeeper
Copy link

I'm seeing something similar on a build using node v14.15.0, npm 6.14.8 and webpack 4.43.0. It happens after installing dat-sdk:

WARNING in ./node_modules/sodium-javascript/randombytes.js 23:6-13
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/sodium-javascript/index.js
 @ ./node_modules/sodium-universal/index.js
 @ ./node_modules/hypercore-crypto/index.js
 @ ./node_modules/dat-sdk/index.js
 @ ./src/containers/pages/settings.tsx
 @ ./src/containers/pages/index.ts
 @ ./src/components/content.tsx
 @ ./src/components/pages/main.tsx
 @ ./src/components/root.tsx
 @ ./src/components/index.tsx
 @ multi @babel/polyfill ./src/components/index.tsx

ERROR in ./node_modules/sodium-javascript/memory.js
Module not found: Error: Can't resolve 'worker_threads' in '/Users/sh601/gitRepos/Storefront-minima/node_modules/sodium-javascript'
 @ ./node_modules/sodium-javascript/memory.js 3:50-80
 @ ./node_modules/sodium-javascript/index.js
 @ ./node_modules/sodium-universal/index.js
 @ ./node_modules/hypercore-crypto/index.js
 @ ./node_modules/dat-sdk/index.js
 @ ./src/containers/pages/settings.tsx
 @ ./src/containers/pages/index.ts
 @ ./src/components/content.tsx
 @ ./src/components/pages/main.tsx
 @ ./src/components/root.tsx
 @ ./src/components/index.tsx
 @ multi @babel/polyfill ./src/components/index.tsx

I've managed to get my project building by hacking a couple of your files:

In memory.js, I commented out if (MessageChannel == null) ({ MessageChannel } = require('worker' + '_threads')) on line 3.

And in randombytes.js, I commented out if (require != null) { (and its associated curly brace) on line 23.

But I know 'me bad' :( Is this an easy fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants