简体   繁体   English

错误TS2304:使用业力打字稿时找不到名称“地图”

[英]error TS2304: Cannot find name 'Map' when using karma-typescript

I try to run my first spec.ts file with karma-typescript and jasmine. 我尝试使用业力打字稿和茉莉花运行我的第一个spec.ts文件。

I already had a lot of different errors that I googled and "fixed" but I'm always getting just other problems. 我已经搜索并“修复”了许多不同的错误,但是我总是遇到其他问题。

  • I added different entries in tsconfig.json->compilerOptions->"lib" 我在tsconfig.json-> compilerOptions->“ lib”中添加了不同的条目
  • tried to change the target 试图改变目标
  • tried out @types/core-js with version 0.9.46 and with 0.9.35 尝试了@ types / core-js版本0.9.46和0.9.35
  • updated node from 8.9.4 to 8.11.2 节点从8.9.4更新到8.11.2
  • tried to downgrade @types/node to some 8.x version 试图将@ types / node降级到某些8.x版本

There is no problem to run the app. 运行该应用程序没有问题。 Just the test does not compile. 只是测试无法编译。

Do I need to configure the compiler of karma differently? 我是否需要以其他方式配置业力的编译器?

At the moment I just use the "minimal karma configuration " from 1 . 目前,我只是用从“最小因缘配置1

module.exports = function(config) {
config.set({
    frameworks: ["jasmine", "karma-typescript"],
    files: [
        "src/**/*.ts" // *.tsx for React Jsx
    ],
    preprocessors: {
        "**/*.ts": "karma-typescript" // *.tsx for React Jsx
    },
    reporters: ["progress", "karma-typescript"],
    browsers: ["Chrome"]
  });
};

The current error is 当前错误

> ts-node node_modules/karma/bin/karma start ./karma.conf.js

29 05 2018 15:49:04.611:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.8.3
29 05 2018 15:49:07.176:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6208,55): error TS2304: Cannot find name 'Map'.

29 05 2018 15:49:07.177:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6215,55): error TS2304: Cannot find name 'Set'.

29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6219,64): error TS2304: Cannot find name 'Symbol'.

29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6225,59): error TS2304: Cannot find name 'WeakMap'.

29 05 2018 15:49:07.178:ERROR [compiler.karma-typescript]: node_modules/@types/node/index.d.ts(6226,59): error TS2304: Cannot find name 'WeakSet'.

29 05 2018 15:49:07.179:ERROR [compiler.karma-typescript]: src/commands/persistence/eventStore/inmemory/InMemoryES.ts(14,26): error TS2304: Cannot find name 'Map'.

29 05 2018 15:49:07.257:INFO [compiler.karma-typescript]: Compiled 9 files in 2632 ms.
29 05 2018 15:49:07.287:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
29 05 2018 15:49:07.288:INFO [launcher]: Launching browser Chrome with unlimited concurrency
29 05 2018 15:49:07.334:INFO [launcher]: Starting browser Chrome
29 05 2018 15:49:09.701:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket JvL2wqL-IoqPWKS8AAAA with id 62494987
Chrome 66.0.3359 (Windows 10 0.0.0) ERROR
  {
    "message": "You need to include some adapter that implements __karma__.start method!",
    "str": "You need to include some adapter that implements __karma__.start method!"
  }


Unhandled rejection Error: COMPILATION ERROR
    at maybeWrapAsError (E:\_d_a_t_e_n\programmieren\private\_web\ADB\ADB-Service\node_modules\bluebird\js\release\util.js:61:12)
    at E:\_d_a_t_e_n\programmieren\private\_web\ADB\ADB-Service\node_modules\bluebird\js\release\nodeback.js:38:50

My current tsconfig.json file 我当前的tsconfig.json文件

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es5", "es6", "dom"], // added because of karma problems, did not help though (https://stackoverflow.com/a/39418293/7869582, https://stackoverflow.com/questions/42738623/cannot-find-name-propertykey)
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "outDir": "./dist/",
    "sourceMap": true,
    "pretty": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "typeRoots": [
    "node_modules/@types"
  ]
}

And the dependencies from package.json 还有来自package.json的依赖

{
  "name": "adb-service",
  "version": "0.0.0",
  "private": true,
  "description": "Backend Express Server",
  "main": "node dist/index.js",
  "scripts": {
    "start": "nodemon dist/index.js",
    "dev": "concurrently --kill-others \"tsc -w\" \"nodemon dist/index.js\"",
    "test2": "ts-node node_modules/jasmine/bin/jasmine",
    "test": "ts-node node_modules/karma/bin/karma start ./karma.conf.js"
  },
  "author": "Andymel",
  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.3",
    "mongoose": "^5.1.0"
  },
  "devDependencies": {
    "@types/body-parser": "^1.16.8",
    "@types/express": "^4.11.1",
    "@types/jasmine": "^2.8.7",
    "@types/mongodb": "^3.0.13",
    "@types/mongoose": "^5.0.13",
    "@types/node": "^10.1.3",
    "concurrently": "^3.5.1",
    "jasmine": "^3.1.0",
    "karma": "^2.0.2",
    "karma-chrome-launcher": "^2.2.0",
    "karma-jasmine": "^1.1.2",
    "karma-typescript": "^3.0.12",
    "nodemon": "^1.17.3",
    "ts-node": "^6.0.5",
    "typescript": "^2.8.3"
  }
}

Thanks in advance for any tip! 在此先感谢您的提示!

I try to start the test with npm test . 我尝试从npm test开始npm test
I successfully run the app with npm run dev 我使用npm run dev成功运行了该应用npm run dev

I added the following lines to karma.config.js (inspired by this github issue ) 我在karma.config.js中添加了以下几行(受此github问题的启发)

karmaTypescriptConfig: {
    compilerOptions: {
        target: "ES2015",
        lib: ["es5", "es6", "es2015", "dom"]
    },
    tsconfig: "tsconfig.json"
},

This removes the compiler errors. 这消除了编译器错误。 I get runtime errors now, but that's another issue. 我现在遇到运行时错误,但这是另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeScript错误:TS2304:找不到名称'日期' - TypeScript error: TS2304:Cannot find name 'Date' TypeScript 收到错误 TS2304:找不到名称“require” - TypeScript getting error TS2304: cannot find name ' require' 打字稿错误:TS2304:找不到名字'$' - typescript error: TS2304: Cannot find name '$' NestJS / Typescript 错误 TS2304 - 找不到名称“Get” - NestJS / Typescript error TS2304 - Cannot find name 'Get' 打字稿错误:TS2304 找不到名称 - Typescript error :TS2304 cannot find name 打字稿错误TS2304:在aurelia-binding@1.0.0-beta.1.3.6中找不到名称“地图” - Typescript error TS2304: Cannot find name 'Map' in aurelia-binding@1.0.0-beta.1.3.6 使用谷歌 api 库编译 typescript 时出现“错误 TS2304:找不到名称‘Long’” - "error TS2304: Cannot find name 'Long'" when compiling typescript with google api libraries 使用带有脚本的easyljs:错误TS2304:找不到名称'EventDispatcher' - Using easeljs with typescript: error TS2304: Cannot find name 'EventDispatcher' TS2304 TypeScript (TS) 找不到名称 - TS2304 TypeScript (TS) Cannot find name 打字稿:错误TS1056和TS2304找不到名称可迭代-SignalR .NET Core 2.2 - typescript: error TS1056 and TS2304 Cannot find name Iterable - SignalR .NET Core 2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM