【问题标题】:Visual Studio Code: "'tslib' cannot be found" error in Angular projectVisual Studio Code:Angular 项目中的“'tslib' 找不到”错误
【发布时间】:2019-10-28 13:13:30
【问题描述】:

基本上,我所做的只是启动一个新的 Angular 项目并将其加载到工作区中。由于这个错误,看起来 VS Code 无法进行任何 linting 或代码感知。它正在吐出这个错误数据:

{
    "resource": "/Users/<snip!>/angular-project/src/app/app.module.ts",
    "owner": "typescript",
    "code": "2354",
    "severity": 8,
    "message": "This syntax requires an imported helper but module 'tslib' cannot be found.",
    "source": "ts",
    "startLineNumber": 13,
    "startColumn": 1,
    "endLineNumber": 26,
    "endColumn": 3
}

我在某处发现了一个旧错误,说必须将 tsconfig.json 中的 moduleResolution 设置为 node,但 Angular CLI 已经为我做到了...

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

编辑:我采取的步骤(在撰写本文时使用版本 8):

  1. 安装 Angular CLI:$ npm install -g @angular/cli
  2. 创建项目:$ ng new angular-project
  3. 服务项目:$ ng serve

有人知道怎么解决吗?

【问题讨论】:

  • 什么是角度版本?您也可以上传显示错误的代码或截屏吗
  • 我可以...但我尝试操纵代码以试图摆脱它,并且项目中任何被评估的代码都会给出相同的错误。
  • FWIW 我正在使用最新的 Angular 工具和 CLI。版本 8.0.2

标签: node.js angular typescript visual-studio-code single-page-application


【解决方案1】:

下面是我使用 Angular 8 的 package.json 文件。检查你是否安装了 tslib。

同时删除 package-lock.json 并删除 node_modules 文件夹,然后再次运行 npm i

{
  "name": "ngrx",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.0.0",
    "@angular/common": "~8.0.0",
    "@angular/compiler": "~8.0.0",
    "@angular/core": "~8.0.0",
    "@angular/forms": "~8.0.0",
    "@angular/platform-browser": "~8.0.0",
    "@angular/platform-browser-dynamic": "~8.0.0",
    "@angular/router": "~8.0.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.800.0",
    "@angular/cli": "~8.0.0",
    "@angular/compiler-cli": "~8.0.0",
    "@angular/language-service": "~8.0.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  }
}

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2018-09-05
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多