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

___tsxInteropDynamicImport is not defined when using worker_threads #384

Closed
3 of 5 tasks
axmad386 opened this issue Nov 14, 2023 · 3 comments · Fixed by #385
Closed
3 of 5 tasks

___tsxInteropDynamicImport is not defined when using worker_threads #384

axmad386 opened this issue Nov 14, 2023 · 3 comments · Fixed by #385
Labels
bug Something isn't working outdated

Comments

@axmad386
Copy link

axmad386 commented Nov 14, 2023

Precheck

  • I searched existing issues before opening this one to avoid duplicates
  • I'm able to reproduce this issue and prove it with a minimal reproduction
  • I understand this is not a place to ask for free debugging support

Problem

I think the problem is similar to this #382. But I found different case. I create minimal reproduce below. It's just simple scheduler using breejs. When I run tsx index.ts it will run the scheduler every 10 second just to console.log. Then this error is occured

Worker for job "hello script" had an error {
  err: ReferenceError [Error]: ___tsxInteropDynamicImport is not defined
      at [worker eval]:1:71
      at [worker eval]:1:126
      at Script.runInThisContext (node:vm:123:12)
      at Object.runInThisContext (node:vm:299:38)
      at node:internal/process/execution:82:21
      at [worker eval]-wrapper:6:24
      at runScript (node:internal/process/execution:81:62)
      at evalScript (node:internal/process/execution:103:10)
      at MessagePort.<anonymous> (node:internal/main/worker_thread:152:7)
      at [nodejs.internal.kHybridDispatch] (node:internal/event_target:757:20)
}

This error doesn't occure on tsx v3, and I can confirm that if you run the script without node:worker_threads, everything is work fine

// change this
const { workerData } = await import("node:worker_threads");
// to this
const workerData = {};

Expected behavior

Script run and scheduler will print the workerData in the console every 10 seconds

Minimal reproduction URL

https://github.com/axmad386/repro-tsx

Version

v4.1.1

Node.js version

v18.18.2

Package manager

pnpm

Operating system

Linux

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@axmad386 axmad386 added bug Something isn't working pending triage labels Nov 14, 2023
@privatenumber
Copy link
Owner

In this case, basically an eval is happening so it can't reach the closure reference. The same reason you had to dynamically import worker_threads inside path instead of at the top of the file. This issue is closer to #113.

@privatenumber
Copy link
Owner

You'll likely have to clear the cache or run with --no-cache to see it work.

@axmad386
Copy link
Author

Wow thanks for quick fix and your explanation. It's work now

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants