developit / web-worker

Consistent Web Workers in browser and Node.
https://npm.im/web-worker
Apache License 2.0
1.06k stars 55 forks source link

Trying to add node compatibility to worka library #14

Closed GrosSacASac closed 3 years ago

GrosSacASac commented 4 years ago

worka is a library initially built for the web. Last week I made it work with Deno as well with one simple change.

I try to make it work with node as well by using web-worker, however I get the follong error 👍

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:258:15) at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:782:11) at Loader.resolve (node:internal/modules/esm/loader:85:40) at Loader.getModuleJob (node:internal/modules/esm/loader:229:28) at Loader.import (node:internal/modules/esm/loader:164:28) at importModuleDynamically (node:internal/modules/cjs/loader:1026:27) at exports.importModuleDynamicallyCallback (node:internal/process/esm_loader:30:14)
at workerThread (C:\files\worka\node_modules\web-worker\cjs\node.js:196:5) at Object. (C:\files\worka\node_modules\web-worker\cjs\node.js:79:56) at Module._compile (node:internal/modules/cjs/loader:1083:30) { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' }

This is the file url I use: file:///C:/files/worka/sort_worka.js The file is there I double checked.

https://github.com/GrosSacASac/worka/blob/master/examples/node/file_usage.js

As you can see in the comments I tried other things as well but got other errors

Note that the deno example is almost the same and it works

https://github.com/GrosSacASac/worka/blob/master/examples/deno/file_usage.js

To reproduce Win 10 64bit Node 15.0.0

https://github.com/GrosSacASac/worka

Any help would be appreciated