Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript compiler: Cannot find name 'Map'

I have Electron + Angular app. I would like to use Typescript for Electron, so I have main.ts file and want to compile it to main.js using 'tsc main.ts'. However, I get the following error:

node_modules/@types/selenium-webdriver/remote.d.ts:139:29 - error TS2304: Cannot find name 'Map'.

Still main.js is generated and can be used when i run electron without tsc command. However, I would like it run by one script without any error.

My tsconfig.json contains:

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

I've already tried various combinations of target and lib configuration (e.g. es6) but with no success.

Can anybody please help? Many thanks!

like image 875
Michal Pinka Avatar asked Dec 06 '22 11:12

Michal Pinka


2 Answers

When you run tsc main.ts, your tsconfig.json file is not being used. Instead run tsc -p . or simply tsc, and if necessary, restrict the input files to the compilation using the files, include, and exclude options in tsconfig.json.

like image 159
Matt McCutchen Avatar answered Dec 09 '22 14:12

Matt McCutchen


For some reason, when I added the include and exclude sections as above, I still got errors:

"../node_modules/@types/selenium-webdriver/http.d.ts:24:14 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later" 

The errors stopped when I ran: npm i @types/node

I would love to know why (:

like image 24
Sebastian Mansfield-Barry Avatar answered Dec 09 '22 14:12

Sebastian Mansfield-Barry