SolvedDefinitelyTyped error TS2304: Cannot find name 'Set'. 815 allowedNodeEnvironmentFlags: Set<string>;

D:\workshop\www
λ node -v
v8.12.0

D:\workshop\www
λ npm -v
6.4.1

D:\workshop\www
λ npm install typescript -g
C:\Users\dell\AppData\Roaming\npm\tsc -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\dell\AppData\Roaming\npm\tsserver -> C:\Users\dell\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
+ typescript@3.0.3
updated 1 package in 3.061s

D:\workshop\www
λ tsc --version
Version 3.0.3

D:\workshop\www
λ mkdir typescript_learning

D:\workshop\www
λ cd typescript_learning

D:\workshop\www\typescript_learning
λ npm init -y
Wrote to D:\workshop\www\typescript_learning\package.json:

{
  "name": "typescript_learning",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



D:\workshop\www\typescript_learning  (typescript_learning@1.0.0)
λ tsc --init
message TS6071: Successfully created a tsconfig.json file.

D:\workshop\www\typescript_learning  (typescript_learning@1.0.0)
λ npm install @types/node --dev-save
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN typescript_learning@1.0.0 No description
npm WARN typescript_learning@1.0.0 No repository field.

+ @types/node@10.11.0
added 1 package from 30 contributors in 1.657s

D:\workshop\www\typescript_learning  (typescript_learning@1.0.0)
λ touch helloworld.ts

D:\workshop\www\typescript_learning  (typescript_learning@1.0.0)
λ tsc helloworld.ts
node_modules/@types/node/index.d.ts:815:38 - error TS2304: Cannot find name 'Set'.

815         allowedNodeEnvironmentFlags: Set<string>;

helloworld.ts

var a:string = "HelloWorld"
console.log(a)

What should I do?

22 Answers

✔️Accepted Answer

Same here with target and lib as es6.
I've managed to fix this by installing @types/node@12.7.4.

Other Answers:

Add "lib": ["es6"] or higher.

I came across this same issue and was confused because my tsconfig.json has exactly what the error message says to do. Modifying my tsconfig.json further would not fix the issue.

When you pass a file path to tsc, I believe the tsconfig.json is ignored. This is what was happening to me.

tsc src/foo.ts # results in compiler errors stating to upgrade my lib/target
tsc # works fine because my tsconfig.json was specifying a target of es2015 or later

So if you're getting this and your tsconfig.json looks good, double check if you're passing a custom path to the compiler, and potentially ignoring your config.

@brunobertoldi
Yes, I can confirm. Your answer fixes the issue.
Here #29172 (comment)

@andy-ms Thanks. After npm rm @types/node -D, this issue is gone.

More Issues: