I'm using the abc module to create a server. When a post request is made to one of the routes, I spawn a web worker:
app.post('/my-route', async (ctx: Context) => {
const body = await ctx.body();
const worker = new Worker(
new URL('worker.ts', import.meta.url).href,
{ type: 'module' }
);
worker.postMessage(body);
});
But this seems not to work. When I make a request to that specific route, the server crashes with the following log:
error: Uncaught Error: Uncaught ReferenceError: Deno is not defined
const isWindows = Deno.build.os == "windows";
^
at expand_glob.ts:19:19
at Worker.#poll (rt/11_workers.js:178:19)
PS: I'm on Windows 10 Pro - 64 bit, with Deno v1.2.2.
To use the Deno namespace in a worker, you need to set deno: true in the worker options.
To use the Deno namespace in a worker, you need to set
deno: truein the worker options.
No, I'm not using the Deno namespace inside the worker. I still tried setting the deno: true option and the error changed to this:
```
error: Uncaught Error: Uncaught NotFound: The system cannot find the path specified. (os error 3)
at Worker.#poll (rt/11_workers.js:190:19)
No, I'm not using the Deno namespace inside the worker
Judging from the error you describe in the original post, it seems like you are. Can you perhaps share what you're doing in your worker?
@ShreyashSaitwal
The first issue: you are importing https://deno.land/x/std/fs/expand_glob.ts somewhere (maybe in a different module you import in the worker). std/fs requires the Deno global to be present. The first issue is thus correct.
The second issue: this error occurs because you are passing some directory into the expandGlob function that does not exist. If you pass in a valid (existing) directory it will work.
No, I'm not using the Deno namespace inside the worker
Judging from the error you describe in the original post, it seems like you are. Can you perhaps share what you're doing in your worker?
Based on the data I receive to the workers, I create directories and copy a bunch of files using the fs module.
@ShreyashSaitwal
The first issue: you are importing https://deno.land/x/std/fs/expand_glob.ts somewhere (maybe in a different module you import in the worker).
std/fsrequires the Deno global to be present. The first issue is thus correct.
Yes, I'm importing the fs module but not expand_glob.ts from it. I'm importing the these functions: ensureDirSync, copy, copySync, writeJson, writeJsonSync.
The second issue: this error occurs because you are passing some directory into the expandGlob function that does not exist. If you pass in a valid (existing) directory it will work.
No, I'm not using the expandGlob function.
@ShreyashSaitwal some code snippet would be nice, otherwise we're pretty much in the dark with what you're trying to do.
@ShreyashSaitwal some code snippet would be nice, otherwise we're pretty much in the dark with what you're trying to do.
Sure, here's a snippet from worker.ts:
import { ensureDirSync } from 'https://deno.land/[email protected]/fs/mod.ts';
// Redacted code...
self.onmessage = async (e: MessageEvent) => {
const body: BuildReq = e.data;
const { email, data } = body;
const dirPath = `./../plugin/${email}/`;
// Redacted code...
ensureDirSync(`${dirPath}/files/`);
// Redacted code...
}
And this one's from server.ts:
app.post('/my-route', async (ctx: Context) => {
const body = await ctx.body();
// Redacted code...
const worker = new Worker(
new URL('worker.ts', import.meta.url).href,
{ type: 'module' }
);
worker.postMessage(body);
// Redacted code...
});
./../plugin/${email}/ & ${dirPath}/files/ make ./../plugin/${email}//files/, which is an invalid path
Using path.join from std would fix this
path.join(`./../plugin/${email}`, "files")
./../plugin/${email}/&${dirPath}/files/make./../plugin/${email}//files/, which is an invalid path
Damn! I'm so stupid. 🤦♂️ I didn't notice that. Thanks for pointing it out.
Most helpful comment
./../plugin/${email}/&${dirPath}/files/make./../plugin/${email}//files/, which is an invalid path