本文介绍了@ngx-translate/core 中的错误 - 错误 TS1086:无法在 Angular 8 的环境上下文中声明访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular 8 并使用 ngx-translate 实现国际化 (i18n).我使用了以下库.

I am using Angular 8 and implementing Internationalization (i18n) using ngx-translate. I have used the following libraries.

  1. @ngx-translate/core":^13.0.0",
  2. @ngx-translate/http-loader":^6.0.0".

在运行这个 angular 项目时,我遇到了那个错误.

At running this angular project, I got that error.

请帮我修正这个错误.

这是完整的错误:

ERROR in node_modules/@ngx-translate/core/lib/translate.directive.d.ts:14:9 - error TS1086: An accessor cannot be declared in an ambient context.

    node_modules/@ngx-translate/core/lib/translate.directive.d.ts:15:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:49:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:56:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:63:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:67:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:68:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:72:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:73:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:77:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:78:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:82:9 - error TS1086: An accessor cannot be declared in an ambient context.
    node_modules/@ngx-translate/core/lib/translate.service.d.ts:83:9 - error TS1086: An accessor cannot be declared in an ambient context.

这是我的 package.json

And here's my package.json

{
  "name": "ng-i18n",
  "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.2.14",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^6.0.0",
    "bootstrap": "^4.0.0",
    "jquery": "^3.5.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.28",
    "@angular/cli": "~8.3.28",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@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": "~7.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

推荐答案

更新

由于最近发布了 angular 11,请检查答案是否仍然与更新的软件包一致.跟踪 ngx-translate 的演变.

Update

Since angular 11 was recentrly released check if the answer is still consistent with the updated packages. Keep track of evolution of ngx-translate.

将其降级到 12.1.2 版对我有用.只需在终端中执行 npm i @ngx-translate/[email protected] 即可.现在我正在使用这些软件包,一切正常:

Downgrading it to the version 12.1.2 worked for me.Simply execute npm i @ngx-translate/[email protected] in your terminal.Right now i'm working with theese packages and everything works fine:

这篇关于@ngx-translate/core 中的错误 - 错误 TS1086:无法在 Angular 8 的环境上下文中声明访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 10:43