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

How does piscina load ts files? #742

Open
Wu1905 opened this issue Feb 14, 2025 · 2 comments
Open

How does piscina load ts files? #742

Wu1905 opened this issue Feb 14, 2025 · 2 comments

Comments

@Wu1905
Copy link

Wu1905 commented Feb 14, 2025

export function registerWorker(threadName: number, filePath: string, isTypescript: boolean = true, maxThreads: number = 4) {
  if (filePath.startsWith("@")) {
    // atPath is project root path
    filePath = path.join(atPath, filePath.slice(2) + (isTypescript ? '.ts' : '.js'));
  }
  const pool = new Piscina({
    filename: filePath,
    maxThreads,
   // !!: Hear, it is not work.But it is work in worker_threads
    ...(isTypescript ? { execArgv: ['-r', 'ts-node/register'] } : {}),
  })
  return pool;
}
@Wu1905
Copy link
Author

Wu1905 commented Feb 14, 2025

run this function, i got this:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for ....
    at new NodeError (node:internal/errors:405:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:136:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:182:36)
    at defaultLoad (node:internal/modules/esm/load:101:20)
    at ModuleLoader.load (node:internal/modules/esm/loader:417:13)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:288:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at ModuleLoader.#createModuleJob (node:internal/modules/esm/loader:312:17)
    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:265:34)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:251:17) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

@metcoder95
Copy link
Member

We do not run any pre-parser or loader when handling TS files (we sort to only JS files).

It would be interesting to explore the handling of TS files, but currently is not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants