Read arguments from command line - error TS2304: Cannot find name 'process' Read arguments from command line - error TS2304: Cannot find name 'process' node.js node.js

Read arguments from command line - error TS2304: Cannot find name 'process'


Update: September 2016

You need to make sure that the type definitions for Node are available. The way to do this depends on which version of TypeScript you are using.

TypeScript 1

Use Typings to install the definitions.

typings install --save --global env~node

Be sure to include typings/index.d.ts in your tsconfig.json file. Either include it in the "files" array:

"files": ["typings/index.d.ts"]

Or ensure it is omitted from the "exclude" array.

TypeScript 2

In TypeScript 2, definitions can be installed via npm under the @types scope.

npm install --save-dev @types/node

Original Answer: February 2016

You have to make sure the appropriate type definitions are available. Use the typings package manager for this. Install the definitions for node as follows:

typings install --save --ambient node

Now, there are a few ways you can make sure the definitions are available to the compiler. The preferred method is to set up your tsconfig file like so:

{  "exclude": [    "typings/browser.d.ts",    "typings/browser",    "node_modules"  ]}

Or, alternatively:

{  "files": [    "typings/main.d.ts"  ]}

If you are not using a tsconfig file, you can use a reference at the top of your main entry file, like so:

/// <reference path="path/to/typings/main.d.ts" />


This question is at top of Google results when looking for "Cannot find name 'process'", so I'll add my 2 cents to a not-too-unrelated issue here.

If you need to get rid of the error when using if(process.env.NODE_ENV === "production") to strip some code in production with webpack, just add the following declaration before the line:

declare var process: {   env: {       NODE_ENV: string   }};


TypeScript 2 - Windows Users

Since this question is at the top of Google for "ts2304 cannot find name 'process'" I want to add some help for Windows users. I was attempting to use environmental variables from a config file and was stuck with this error.

TSError: Unable to compile TypeScript.

Cannot find name 'process'- (2304)

I finally added this to my tsconfig.json:

{  "compilerOptions": {    "typeRoots": [      "./node_modules/@types"    ]  }}

This was with tsconfig.json and node_modules in the same directory level but for some reason the compiler just was not seeing it. What was strange is this error only occurred for the process.env variables as the rest of my code had no trouble compiling.