Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@types/node installed typescript version not able find module" child_process"

I found typescript version for node unfortunately it's not able find "child_process" module from the node packages.

Exactly the error message in my console is Module not found: Error: Can't resolve 'child_process'

When I went through some blog they recommended to add below code in your tsconfig.json file.

"typeRoots": [
      "node_modules/@types"
    ]

Same thing as I pasted over here unlikely it's did't help.

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Why they don't inject this node module ? Am I doing something wrong in tsconfig.json file? I would be a grateful if you could give a little help. Thanks in advance.

like image 405
QuokMoon Avatar asked Jun 01 '17 10:06

QuokMoon


1 Answers

Maybe is the path:

"typeRoots": [
      "../node_modules/@types"
    ]

Usually you have your tsconfig in a src.

Update:

My original answer makes no sense, because you have this "baseUrl": "src".

As instead, I believe it could be a Webpack issue.

Try adding this to your webpack.config file:

target: 'node'

Update 2:

Workaround: Add the following to your config file:

node: {
      child_process: 'empty'
}
like image 74
SrAxi Avatar answered Nov 19 '22 08:11

SrAxi