1 year ago

#386496

test-img

AhmadKajjan

I am try to running child process fork with typescript from the dist folder but it's not working without using ts-node

hello everyone I am building a typescript node app and I was trying to change my code to use ES7 instead of CommonJs because I need to make my code run only using the dist folder "typescript output" as a pure javascript project even if my typescript project doesn't exist. After a lot of changes, I ran into an issue because I am using "ChildProcess fork" in my code and when I changed its path to "./dist/src/problem/index.js" instead of "./src/problem/index.ts" the process didn't start

here is my package.json

  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "type": "module",
  "scripts": {
  "build": "tsc --w",
  "start": "tsc && node  --experimental-specifier-resolution=node ./dist/src/index.js",
  }

and my tsconfig.json file

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "downlevelIteration": true,
    "strict": true,
    "target": "ES2017",
    "lib": ["es2017"],
    "outDir": "./dist",
    "skipLibCheck": true
  },
  "include": [
    "./src/**/*.ts",
    "src/**/*.json",
    "tests/**/*.ts",
    "tests/**/*.json"
  ]
}

and the part where I run the "ChildProcess" looks like this:

const childProcess = fork("./dist/src/problem/index.js");
this.childProcesses.push(childProcess);

javascript

node.js

typescript

child-process

0 Answers

Your Answer

Accepted video resources