10

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!

1
  • Your target and lib properties are fine. It's probably something to do with typeRoots. Perhaps the library depends on a version of the nodejs types or something and it is installed in a subdirectory due to multiple versions Commented Sep 23, 2018 at 20:45

5 Answers 5

18

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.

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

3 Comments

Many thanks Matt, solved by changing command to just tsc and by adding include and exclude sections before compilerOptions in tsconfig.json
@MichalPinka, I am facing the same error, can you show me your tsconfig.json file..??
@METALHEAD { "compileOnSave": false, "include": [ "main.ts", "src/**/*" ], "exclude": [ "node_modules" ], "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" ] } }
13

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 (:

1 Comment

npm i @types/node worked for me too , where did you find this in documentation, i would like to read more
1

I had this issue after upgrading from Angular 6 to Angular 8. Turns out the upgrade script updates the Typescript version, but the @types/node package was outdated in my package.json (and apparently, not compatible anymore with the new Typescript version). Updating it did the trick !

Comments

0

Make sure your library name is similar at .json file Install npm gulp and ci

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
-1

I had the same problem.

Try to execute the following command:

npm ci

On my PC it fixed

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.