typescript [at-loader] node_modules\@types\jasmine 中的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42181156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:15:28  来源:igfitidea点击:

ERROR in [at-loader] node_modules\@types\jasmine

angulartypescriptnpmwebpackjasmine

提问by Josh

My webpack build started failing out of nowhere with no packages being updated. I assume some minor version update caused this, but can't figure out how to get around it. Does anyone know what to do?

我的 webpack 构建开始突然失败,没有更新任何包。我假设一些小版本更新导致了这个,但无法弄清楚如何解决它。有谁知道该怎么做?

ERROR in [at-loader] node_modules\@types\jasmine\index.d.ts:39:52 
    TS1005: '=' expected.
ERROR in [at-loader] node_modules\@types\jasmine\index.d.ts:39:38 
    TS2371: A parameter initializer is only allowed in a function or constructor implementation.
ERROR in [at-loader] node_modules\@types\jasmine\index.d.ts:39:46 
    TS2304: Cannot find name 'keyof'.

package.json

包.json

  "dependencies": {
    "@angular/common": "2.4.7",
    "@angular/compiler": "~2.4.4",
    "@angular/core": "2.4.7",
    "@angular/forms": "2.4.7",
    "@angular/http": "~2.4.4",
    "@angular/material": "^2.0.0-beta.1",
    "@angular/platform-browser": "~2.4.4",
    "@angular/platform-browser-dynamic": "~2.4.4",
    "@angular/platform-server": "~2.4.4",
    "@angular/router": "~3.4.1",
    "@angularclass/conventions-loader": "^1.0.2",
    "@angularclass/hmr": "~1.2.2",
    "@angularclass/hmr-loader": "~3.0.2",
    "@vaadin/angular2-polymer": "^1.0.0",
    "animate.css": "^3.5.2",
    "assets-webpack-plugin": "^3.4.0",
    "bootstrap-sass": "^3.3.7",
    "bootstrap-select": "^1.12.1",
    "bootstrap-tour": "^0.11.0",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "http-server": "^0.9.0",
    "icheck": "^1.0.2",
    "ie-shim": "^0.1.0",
    "jasmine-core": "^2.5.2",
    "metismenu": "2.0.2",
    "nestable": "^0.2.0",
    "ng2-modal": "0.0.24",
    "ng2-tag-input": "~0.8.4",
    "pace": "0.0.4",
    "pace-progress": "^1.0.2",
    "primeng": "^1.1.4",
    "reflect-metadata": "^0.1.9",
    "rxjs": "~5.1.0",
    "summernote": "^0.8.2",
    "zone.js": "0.7.4",
    "ag-grid": "~8.0.1",
    "ag-grid-enterprise": "~8.0.1",
    "ag-grid-ng2": "~8.0.0"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~2.4.1",
    "@types/hammerjs": "^2.0.33",
    "@types/jasmine": "^2.2.34",
    "@types/node": "^6.0.38",
    "@types/selenium-webdriver": "2.53.38",
    "@types/source-map": "^0.5.0",
    "@types/uglify-js": "^2.0.27",
    "@types/webpack": "^2.0.0",
    "angular-router-loader": "^0.4.0",
    "angular2-template-loader": "^0.6.0",
    "assets-webpack-plugin": "^3.4.0",
    "awesome-typescript-loader": "~3.0.4-rc.2",
    "codelyzer": "~2.0.0-beta.4",
    "copy-webpack-plugin": "^4.0.0",
    "css-loader": "^0.26.0",
    "exports-loader": "^0.6.3",
    "expose-loader": "^0.7.1",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",
    "file-loader": "^0.9.0",
    "gh-pages": "^0.12.0",
    "html-webpack-plugin": "^2.21.0",
    "imports-loader": "^0.7.0",
    "istanbul-instrumenter-loader": "1.2.0",
    "jasmine-core": "^2.5.2",
    "json-loader": "^0.5.4",
    "karma": "^1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.0.2",
    "karma-mocha-reporter": "^2.0.0",
    "karma-remap-coverage": "^0.1.4",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "1.8.1",
    "ngc-webpack": "^1.0.2",
    "node-sass": "^4.1.1",
    "npm-run-all": "^4.0.0",
    "parse5": "^3.0.1",
    "protractor": "^4.0.10",
    "raw-loader": "0.5.1",
    "rimraf": "~2.5.4",
    "sass-loader": "^4.1.1",
    "script-ext-html-webpack-plugin": "^1.3.2",
    "source-map-loader": "^0.1.5",
    "string-replace-loader": "1.0.5",
    "style-loader": "^0.13.1",
    "to-string-loader": "^1.1.4",
    "ts-helpers": "1.1.2",
    "ts-node": "^2.0.0",
    "tslint": "4.2.0",
    "tslint-loader": "^3.3.0", 
    "typedoc": "^0.5.3",
    "typescript": "2.0.10",
    "url-loader": "^0.5.7",
    "v8-lazy-parse-webpack-plugin": "^0.3.0",
    "webpack": "2.2.1",
    "webpack-dev-middleware": "^1.10.0",
    "webpack-dev-server": "2.3.0",
    "webpack-dll-bundles-plugin": "^1.0.0-beta.5",
    "webpack-md5-hash": "^0.0.5",
    "webpack-merge": "~2.6.1"
  }

回答by Daniel Mora

Looks like your @types/jasminelibrary was upgraded to the latest version since you have the caret symbol:

看起来您的@types/jasmine库已升级到最新版本,因为您有插入符号:

"@types/jasmine": "^2.2.34",

The latest version is having issues as this bugsuggests. So try for now by setting the version to 2.5.41 in your package.json :

正如此错误所暗示的那样,最新版本存在问题。所以现在尝试通过在 package.json 中将版本设置为 2.5.41 :

"devDependencies": {
  "@types/jasmine": "2.5.41"
}

Maybe you have to delete your node-modulesfolder and run npm installfor a clean installation.

也许您必须删除node-modules文件夹并运行npm install以进行全新安装。

回答by noomorph

If you're not using Angular 2, update your TypeScript to 2.1.6 or higher, please. This should help.

如果您没有使用 Angular 2,请将您的 TypeScript 更新到 2.1.6 或更高版本。这应该有帮助。

According to this discussion, a more correct solution is to keep TypeScript updated to the latest stable minor version of 2.xbranch, which is 2.1.6as of now (Feb 12, 2017). The error you have in a build log indicates that you are using an outdated 2.0.10version. The latest jasminedefinition file has a new syntax check in spyOn()function which is available only for TypeScript >=2.1.0. Generally, you should have no serious reason to stick to 2.0.10, so, please upgrade. However, if there's a backward compatibility issue preventing you from the upgrade, you should fill in the issue form here: https://github.com/Microsoft/TypeScript/issuesand make the compiler team aware of a bug.

根据此讨论,更正确的解决方案是将 TypeScript 更新到最新的稳定次要2.x分支版本,即2.1.6截至目前(2017 年 2 月 12 日)。您在构建日志中的错误表明您使用的是过时的2.0.10版本。最新的jasmine定义文件有一个新的语法检查spyOn()功能,仅适用于 TypeScript >=2.1.0。一般来说,你应该没有严重的理由坚持2.0.10,所以,请升级。但是,如果存在阻止您升级的向后兼容性问题,您应该在此处填写问题表:https: //github.com/Microsoft/TypeScript/issues并使编译器团队意识到错误。

UPD: Avoid in your package.jsonlines like these: "typescript": "2.0.10, "typescript": "~2.0.0". Instead of ~you should apply ^restriction (allows to update minor version numbers, not only hotfixes) like "typescript": ^2.0.0".

UPD:避免在您的package.json行中使用:"typescript": "2.0.10, "typescript": "~2.0.0". 而不是~您应该应用^限制(允许更新次要版本号,而不仅仅是修补程序),例如"typescript": ^2.0.0".

Hope that helps. Sorry for the inconvenience.

希望有帮助。带来不便敬请谅解。

回答by GarouDan

Even with Angular 2+ I had this problem. What solved the problem to me, instead of downgrading Jasmine was updating Typescript.

即使使用 Angular 2+ 我也遇到了这个问题。对我来说解决问题的是更新 Typescript,而不是降级 Jasmine。

My steps were:

我的步骤是:

  • Change package.jsonto point to a new version of typescript
    • "typescript": "~2.0.9"-> "typescript": "^2.0.9"
  • Run npm install
  • After this the error was gone.
  • 更改package.json为指向新版本的打字稿
    • "typescript": "~2.0.9"-> "typescript": "^2.0.9"
  • npm install
  • 在此之后,错误消失了。