136

I am setting up a new project with express+ typescript and facing typescript error - cann't find name 'processs'enter image description here

package.json

"dependencies": {
    "express": "^4.16.4",
    "nodemon": "^1.18.7",
    "tsc": "^1.20150623.0",
    "typescript": "^3.1.6"
  },
  "devDependencies": {
    "@types/express": "^4.16.0",
    "@types/mocha": "^5.2.5",
    "@types/node": "^10.12.10",
    "eslint": "^5.9.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-promise": "^4.0.1",
    "mocha": "^5.2.0",
    "supertest": "^3.3.0",
    "typescript-eslint-parser": "^21.0.1"
  }

I tried to follow the solution and added types tsconfig

{
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "outDir": "dist",
      "sourceMap": true,
      "types": ["node"] -----
    },
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "node_modules"
    ]
}

But I still get the error. I have installed npm (6.4.1) and node (8.14.0) to start building up my new project. Can someone highlight what I am doing wrong?

9 Answers 9

147

Make sure you have "types": ["node"] in your tsconfig.app.json file. Having it in tsconfig.json was not enough for me (Angular 12).

{
  ...
  "compilerOptions": {
    ...
    "types": ["node"]
  },
 ...
}

Sign up to request clarification or add additional context in comments.

2 Comments

This helped me with Vue 3 + Vite.
This was also very helpful to me when using Vue 3 + Vite. It even works when omitting this option in 'tsconfig.config.json': I only had to add this compiler option in the file 'tsconfig.json'
91

Your new configuration looks right. Although, you probably have to restart typescript language server if it still uses previous version of the tsconfig. In order to do this in VS Code, you do Ctrl+Shift+P and Reload Window or TypeScript: Restart TS server if available.

Also you don't need tsc package in your dependencies, because it is deprecated now, and typescript package comes with tsc executable.

4 Comments

Just to point out that it's the @types/node dev dependency that seems to be required to fix this issue. At least, that's what got rid of the error for me.
You may also need a tsconfig.json file typescriptlang.org/docs/handbook/tsconfig-json.html
I did yarn add -D @types/node, then I restarted the TS server, and now it works. I don't have a tsconfig.json, using Node.js v18.9.0
For people coming at this from React/Vite: The tsconfig + Restart TS Server hint will be good for a lot of people
55

Just to point out that it's the @types/node dev dependency that seems to be required to fix this issue. At least, that's what got rid of the error for me. – devklick Jul 8 at 8:42

Using npm:

npm i --save-dev @types/node

Using Yarn: (@netotz)

yarn add -D @types/node

2 Comments

Following this yielded npm ERR! 404 '@typescript-eslint/type-utils@https://registry.npmjs.org/@typescript-eslint/types-utils/-/types-utils-5.19.0.tgz' is not in the npm registry.
yarn add -D @types/node
12

I got the error in /test/*.spec.ts files only.

I didn't want to add @types/node to my main dependencies.

For me, updating my tsconfig.json as follows fixed it:

  "include": [
    "src/**/*.ts",
    "test/**/*.spec.ts"
  ],

1 Comment

Thanks, my file was outside src, moving it inside src fixed the issue.
4

I got this issue today. I had a drizzle.config.ts in the root folder that wasn't included in tsconfig.json.

Update the includes in tsconfig.json

{
   // ...
   "include": ["src/**/*.ts", "*.ts"], // Add every .ts file in the root directory
}

1 Comment

Similar issue here. If the problem occurs in a subdirectory of "src/", then the recursive pattern "src/**/*.ts" is missing. Alternatively, if access to node.js types is needed in only one file, one can add an import: import "node"; in that file.
2

For me this error occurred in the playwright.config.ts file. To fix it I had to add this file to the "include" option in my tsconfig.node.json like so:

{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "es2022",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts", "playwright.config.ts"]
}

Then restart the TS Server in VSCode (see other comment here) and the error was gone.

To sum up: When you see the typescript error Cannot find name 'process' in a file then it is probably not covered by your TS compiler (included in your tsconfig).

Comments

1

Here I had a similar issue, that the --save-dev didnt work, so I would say add the @types/node as a normal dependency instead of a dev one.

enter image description here

3 Comments

You don't need types as dependency because you only use it while developing hence why it's in devDependencies.
@A1rPun but this indeed fixed my problem too. It works when I run it, but for some reason, VS Code type errors unless the types are not in dependencies.
@GolDDranks I think that worked for you as when we are adding on dependecies we can do npm install, and this will be installed on node_modules, if the type isn't on node_modules would be hard to use them. I would say if you want to add as devDependecies you also need to install: npm install --only=dev I think after this you will be able to make it work as devDependecy. I hope this helps!
0

angular 16 (local). This works for me instead of adding 'node' in 'compilerOptions' types.

 "angularCompilerOptions": {
        "types": ["node"],
    ...
    }

Comments

0

If you are using Vite + Vue 3 + Typescript. Create such .env file in the root of your project (prefix VITE for vars is mandatory):

VITE_MY_VAR=MY_VAL_1

Then use such code in your vue app:

const myVar1 = import.meta.env.VITE_MY_VAR;
alert(myVar1)

And you dont need to install @types/node. You dont need to edit tsconfig.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.