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
MongoClient import within Worker throws "Cannot find name 'window'" #248
Comments
I think your deno version is too low or does not give enough permissions |
This happens using Deno 1.13.1 deno 1.13.1 (release, x86_64-apple-darwin) A simple worker.ts containing the import and a main.ts instantiating the worker causes the error. The command for running I use is: deno run --allow-read --allow-net --unstable main.ts |
Perhaps the reason is that crypto is temporarily unavailable in deno's webworker |
If I remove the import and use crypto directly crypto.getRandomValues(new Uint8Array(24)) then there is no error. Accessing crypto through the global object is what is causing the problem when executed within a worker. |
Digging in Deno's discussions in their GitHub, I seem to understand now what the problem is. They intentionally removed 'window' as a valid global object for Workers. The global object 'window' is only available for code executed in the main thread. Worker's threads can access 'globalThis' or 'self'. There was much discussion about existing code being broken by that. I think this is what has happened here. Would be a proper fix for this issue the removal of the reference to 'window' in the code? Or is this module intended to not be used in a worker thread? |
I think we can use |
Should I take care of the change and send a pr? |
This import is causing the following error:
error: Uncaught (in worker "") TS2304 [ERROR]: Cannot find name 'window'.
this.nonce = window.crypto.getRandomValues(new Uint8Array(24));
~~~~~~
at https://deno.land/x/mongo@v0.24.0/src/auth/base.ts:34:18
Not sure whether this is a problem in deno_mongo or Deno itself.
The text was updated successfully, but these errors were encountered: