Angular node_modules/ngx toastr/toastr/toast noanimation.component.d.ts(19,9)

Angular node_modules/ngx toastr/toastr/toast noanimation.component.d.ts(19,9),angular,typescript,angular8,Angular,Typescript,Angular8,shared.module.ts import { animate, state, style, transition, trigger } from '@angular/animations'; import { ToastrModule } from 'ngx-toastr'; import { BrowserModule } from '@angular/platform-browser'; @NgModule({ declarations: [HeaderComponent,

shared.module.ts

import { animate, state, style, transition, trigger } from '@angular/animations';
import { ToastrModule } from 'ngx-toastr';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
    declarations: [HeaderComponent, SidebarComponent],
    imports: [
        CommonModule,
        RouterModule,
        FormsModule,
        NgxDatatableModule,
        ToastrModule.forRoot() // ToastrModule added
    ],
    exports: [
        HeaderComponent,
        SidebarComponent,
        FormsModule,
        NgxDatatableModule,
        ToastrModule,
    ],
    providers: []
})
这是我的共享模块 我已经安装了 npm安装ngx toastr--保存
npm安装@角度/动画-保存

但这给了我一个错误

节点_modules/@angular/animations/browser/browser.d.ts(135,9)中出错:错误TS1086:无法在环境上下文中声明访问器。 node_modules/@angular/animations/browser/browser.d.ts(301,9):错误TS1086:无法在环境上下文中声明访问者。
node_modules/ngx toastr/portal/portal.d.ts(26,9):错误TS1086:无法在环境上下文中声明访问者。 node_modules/ngx toastr/toastr/toast noanimation.component.d.ts(19,9):错误TS1086:无法在环境上下文中声明访问器。 node_modules/ngx toastr/toastr/toast.component.d.ts(26,9):错误TS1086:无法在环境上下文中声明访问器

请推荐这个

package.json文件

{
  "name": "mop",
  "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": "^9.0.1",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^9.0.0",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@fortawesome/fontawesome-free": "^5.12.1",
    "@ng-bootstrap/ng-bootstrap": "^5.2.1",
    "@swimlane/ngx-datatable": "^16.0.3",
    "angular-font-awesome": "^3.1.2",
    "bootstrap": "^4.4.1",
    "font-awesome": "^4.7.0",
    "line-awesome": "^1.3.0",
    "ng2-bootstrap": "^1.6.3",
    "ngx-cookie-service": "^2.3.0",
    "ngx-toastr": "^12.0.0",
    "rxjs": "~6.4.0",
    "save": "^2.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.23",
    "@angular/cli": "~8.3.23",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "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.5.3"
  }
}

请检查您的
包.json
,您可能使用了错误版本的

@angular…
软件包,有些是~9,有些是~8

通过运行以下命令升级Angular: 升级材料
您还可以手动更新
package.json中的版本,并运行
npm install
warn
我也遇到了同样的问题。我已经通过更改package.json中的toastr版本解决了这个问题。我使用了这个“ngx toastr”:“^10.0.4”,而不是这个“ngx toastr”:“^12.0.0”。然后安装npm i.

“ngx toastr”:“^10.0.4”和 “@angular/animations”:“^8.2.14”


对于angular 8,永久修复了我的问题。

您只需检查您使用的angular版本是否使用了正确的ngx toastr版本

ngx-toastr  Angular
6.5.0       4.x
8.10.2      5.x
10.1.0      8.x 7.x 6.x
11.3.3      8.x current >= 9.x
请参见此处的依赖项:

如果您安装的angular版本和toastr版本不匹配,可能会出现此问题

依赖关系

ngx-toastr  |   Angular version
-------------------------------------
6.5.0       |   4.x

8.10.2      |   5.x

10.1.0      |   8.x 7.x 6.x

11.3.3      |   8.x

12.1.0      |   9.x

current     |   >= 10.x
例如,如果您使用的是angular 4 x,那么您应该安装toastr版本6.5.0任何超过6.5.0的版本都可能会给您带来错误

如何安装特定版本的toastr? 如果您已经安装了任何toastr版本,请通过卸载它

npm uninstall ngx-toastr
然后根据您的角度安装一个特定版本的烤面包机

npm install ngx-toastr@Your_version_number
注意:如果问题仍然存在,请检查@angular/animations版本的兼容性

访问:有关更多信息

我没有使用Material请共享您的软件包。jsonAs我提到您有“@angular/animations”:对于版本9,所有其他angular版本都是~8,请对齐到8或9,这将解决您的问题。我认为投票数大于10的答案最好接受。。如果你像我一样思考,请改变
npm uninstall ngx-toastr
npm install ngx-toastr@Your_version_number