Angular 看到错误的 Typescript 版本

标签 angular typescript angular-cli

这个问题在这里已经有了答案:





The Angular Compiler requires TypeScript >=3.4.0 and <3.5.0 but 3.5.3 was found instead

(16 个回答)


1年前关闭。




当我跑 ng build我收到以下错误:

ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.6.0 but 3.7.4 was found instead.



但在我的 package.json , 我已经定义了 "typescript": "^3.5.3"
我在项目中的文件中找到了 3.7.4它没有出现在任何地方,为什么 Angular-CLI 认为这是指定的版本?

我正在使用节点 12.13.0。

这是我的全部package.json :
{
  "name": "my-app",
  "version": "0.0.0",
  "scripts": {
    "postinstall": "npm run build",
    "ng": "ng",
    "dev": "ng build --aot --watch",
    "dtos": "tsd-ref && ts-ref",
    "build": "ng build --prod",
    "publish": "npm run build",
    "lint": "ng lint",
    "test": "ng test",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/common": "^8.2.14",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/forms": "^8.2.14",
    "@angular/http": "^7.2.15",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "^8.2.14",
    "@angular/router": "^8.2.14",
    "@servicestack/angular": "0.0.8",
    "@servicestack/client": "^1.0.31",
    "bootstrap": "^4.4.1",
    "core-js": "^3.6.1",
    "rxjs": "^6.5.4",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.21",
    "@angular/cli": "^8.3.21",
    "@angular/compiler-cli": "^8.2.14",
    "@angular/language-service": "^8.2.14",
    "@types/jasmine": "^3.5.0",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^12.12.22",
    "codelyzer": "^5.2.1",
    "gulp": "^4.0.2",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~3.0.0",
    "karma-coverage-istanbul-reporter": "^2.1.1",
    "karma-jasmine": "^2.0.1",
    "karma-jasmine-html-reporter": "^1.5.1",
    "protractor": "^5.4.2",
    "ts-node": "^8.5.4",
    "tslint": "^5.20.1",
    "typescript": "^3.5.3"
  }
}

最佳答案

npm semver docs解释不同运算符的含义,例如^Caret Ranges允许升级到下一个主要版本。

您可以使用 ~Tilde Ranges而是允许补丁级别更改:

"typescript": "~3.5.3"

或者指定使用 准确版本您应该指定版本号(假定隐含 = 默认值),例如:
"typescript": "3.5.3"

关于Angular 看到错误的 Typescript 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59515076/

相关文章:

html - Angular 2 '@Component' 装饰器是否总是需要一个元素名称选择器?

Angular2 访问模板变量的值,

javascript - typescript 使用 map 进行迭代并使用索引获取键,值和删除项目

angularjs - 将 Angular CLI 与 Squarespace 集成

node.js - 在 Heroku 上构建 Angular 4 应用程序时,不包括 Assets

Angular 4 找不到名称 'ViewChild'

linux - Manage ctrl+z and bg or & signal in shell script - (shell脚本中的后台进程)

html - 如何设置继承自父ngb下拉菜单的宽度附加到主体?

angular - 使用 [ngClass] 条件只能正确显示一种 Font Awesome 图标

angular-cli - 浏览器加载 index.html 的缓存版本 - angular 7