ts-node error: Cannot find module 'process' or its corresponding type declarations

9.5k Views Asked by At

ts-node is giving me this error:

Cannot find module 'process' or its corresponding type declarations.

This is my tsconfig.json

{
  "compilerOptions": {
    "types": [ "node "],
    "declaration": true,
    "target": "ESNext",
    "module": "CommonJS",
    "outDir": "./dist",
    "rootDir": "./src",
    "moduleResolution": "node"
  }
}

This is my package.json

{
  "name": "example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "Seph Reed",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^14.14.9",
    "ts-node": "^9.0.0",
    "typescript": "^4.1.2"
  }
}

Why am I getting this error?

1

There are 1 best solutions below

0
On BEST ANSWER

So dumb. There's a space in "types": [ "node "], above.

Also, you only get the error I listed if you import like this:

import { argv } from 'process';

If you just use the variable without an import statement, you get the error:

Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node and then add node to the types field in your tsconfig.

I'm going to leave this question un-deleted for searchability sake. I really couldn't find this error listed anywhere else.