Overview

How would one start a worker thread with ts-node? Every attempt that I've made leads to a MODULE_NOT_FOUND error.

Various Attempts

Currently, I'm attempting to spawn a new worker thread using this syntax:

new Worker("fileToRunAsWorkerThread.ts");

That results in a ERR_UNKNOWN_FILE_EXTENSION: Unknown file extension ".ts" error. I have also tried:

  • Passing no file extension (fileToRunAsWorkerThread) (MODULE_NOT_FOUND)
  • Passing the file with a Javascript file extension a Javascript extension (fileToRunAsWorkerThread.js), both resulting in the same MODULE_NOT_FOUND error (the actual file is still .ts).

I also tried passing different environment variables, as shown in the ts-node documentation https://typestrong.org/ts-node/docs/recipes/other/, all of which returned the same MODULE_NOT_FOUND error, in combination with all of the different file extension combinations shown above.

Environment configuration:

tsconfig.json:

{
    "compilerOptions": {
        "esModuleInterop": true,
        "module": "ESNext",
        "target": "ESnext",
        "lib": ["ESNext"],
        "outDir": "target",
        "sourceMap": true,
        "moduleResolution": "node"
    },
    "ts-node": {
        "files": true,
        "swc": true,
        "esm": true
    }
}

Relevant sections of package.json:

    "main": "./core/main.ts",
    "type": "module",

Node version: v17.3.0

TS-node version: v10.9.1

Typescript version: v5.0.2

Any help would be greatly appreciated, let me know if there's any ways I could improve my question!

EDIT

I gave up and switched to TSC.

0

There are 0 best solutions below