You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a program using Node.js, TypeScript and a lib called microjob. the program code below:
exportclassEnvChecker{staticasynccheckRuntimes(){// 首先通过进程命令行获取运行时类型(node/tsx/deno/bun...)constwillCheck=process.env.EC_ON_LAUNCH||falseif(willCheck){try{// start the worker pool firstawaitstart({maxWorkers: 1})// this function will be executed in another threadconstres=awaitjob(()=>{console.log(`run time is: ${process.argv[0]}`)// doing some other tasks, skip herereturn'Env check done.'})console.log(res)}catch(err){console.error(err)}finally{awaitstop()// shutdown worker pool}}}}EnvChecker.checkRuntimes()
When I execute it use deno, got error:
PS F:\my-program> npm run dev:deno
> deno run --watch --inspect --allow-all src/main.tsWatcher Process started.Debugger listening on ws://127.0.0.1:9229/ws/3426a06b-7d14-4a71-bdca-e45de5e07894Visit chrome://inspect to connect to the debugger.Debugger listening on ws://127.0.0.1:9229/ws/0ef0d61e-7b4c-4b57-94bc-2633e8907f82Visit chrome://inspect to connect to the debugger.error: Uncaught (in worker "[worker eval]") SyntaxError: Unexpected identifier 'parentPort' at <anonymous> (data:text/javascript,const { parentPort }......error(err) } }}):1:49)2024/11/30 13:16:01 Web app > Main Process launched, name: Mot&Mot2024/11/30 13:16:01 Web app > Server is running on port: 555012024/11/30 13:16:01 Web app > Process(Whole App/Service) instance xid(random): ct59v4cn97dj54118l2g, OS process id: 12944Debugger listening on ws://127.0.0.1:9229/ws/955a666c-c547-46c9-a6f8-7fea6490b9d5Visit chrome://inspect to connect to the debugger.error: Uncaught (in worker "[worker eval]") SyntaxError: Unexpected identifier 'parentPort' at <anonymous> (data:text/javascript,const { parentPort }......error(err) } }}):1:49)[Object: null prototype] { message: "Uncaught SyntaxError: Unexpected identifier 'parentPort'", fileName: "data:text/javascript,const { parentPort } = require('worker_threads')parentPort.on('message', async worker => { const response = { error: null, data: null } try { eval(worker) // __executor__ is defined in worker response.data = await __executor__() parentPort.postMessage(response) } catch (err) { response.data = null response.error = { message: err.message, stack: err.stack } try { parentPort.postMessage(response) } catch (err) { console.error(err) } }})", lineNumber: 1, columnNumber: 49}
Meanwhile, this program works fine in node/tsx and bun:
PS F:\my-program> npm run dev:tsx
> npx tsx watch --inspect --env-file=.env src/main.tsDebugger listening on ws://127.0.0.1:9229/085d4c46-186c-43c4-9676-95fc522e81c4For help, see: https://nodejs.org/en/docs/inspectorrun time is: C:\Apps\Nvm\Node\node.exeEnv check done.
PS F:\my-program> npm run dev:bun
> bun run --watch --inspect src/main.ts--------------------- Bun Inspector ---------------------Listening: ws://localhost:6499/m4h84jh099gInspect in browser: https://debug.bun.sh/#localhost:6499/m4h84jh099g--------------------- Bun Inspector ---------------------run time is: C:\Users\jason\scoop\apps\bun\1.1.38\bun.exeEnv check done.
The text was updated successfully, but these errors were encountered:
marvinhagemeister
changed the title
When running thread pool, got error: Uncaught (in worker "[worker eval]") SyntaxError: Unexpected identifier 'parentPort'
Node worker_threads: SyntaxError: Unexpected identifier 'parentPort'
Dec 2, 2024
marvinhagemeister
changed the title
Node worker_threads: SyntaxError: Unexpected identifier 'parentPort'
SyntaxError: Unexpected identifier 'parentPort' in worker_threads
Dec 2, 2024
Version: Deno 2.1.2, Windows 10 x64
I wrote a program using Node.js, TypeScript and a lib called microjob. the program code below:
When I execute it use deno, got error:
Meanwhile, this program works fine in node/tsx and bun:
The text was updated successfully, but these errors were encountered: