打字稿编译器:找不到名称“地图”

Mic*_*nka 3 typescript electron angular

我有Electron + Angular应用程序。我想将Typescript用于Electron,所以我有main.ts文件,并想使用“ tsc main.ts”将其编译为main.js。但是,出现以下错误:

node_modules/@types/selenium-webdriver/remote.d.ts:139:29-错误TS2304:找不到名称“地图”。

仍然会生成main.js,并且当我运行电子时无需使用tsc命令。但是,我希望它由一个脚本运行而没有任何错误。

我的tsconfig.json包含:

{
 "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"
  ]
 }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了目标和库配置的各种组合(例如es6),但没有成功。

有人可以帮忙吗?非常感谢!

Mat*_*hen 5

运行时tsc main.tstsconfig.json没有使用您的文件。相反,运行tsc -p .或根本tsc,并在必要时限制使用的输入文件的编制filesinclude以及exclude期权tsconfig.json


小智 5

出于某种原因,当我添加上面的包含和排除部分时,我仍然遇到错误:

"../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" 
Run Code Online (Sandbox Code Playgroud)

当我运行时,错误停止了: npm i @types/node

我很想知道为什么(:

  • `npm i @types/node` 也为我工作,你在文档中哪里找到这个,我想阅读更多 (2认同)