错误TS1086:无法在Angular 9中的环境上下文中声明访问器
我正在学习Angular材质,从“@Angular/Material/button”导入{MatButtonModule}时出现此错误 从我在其他答案中读到的内容来看,它看起来像是包兼容性问题,但我无法修复它 这是全部错误错误TS1086:无法在Angular 9中的环境上下文中声明访问器,angular,angular-material,Angular,Angular Material,我正在学习Angular材质,从“@Angular/Material/button”导入{MatButtonModule}时出现此错误 从我在其他答案中读到的内容来看,它看起来像是包兼容性问题,但我无法修复它 这是全部错误 ERROR in node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(29,9): error TS1086: An accessor cannot be declared in an ambient conte
ERROR in node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(29,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(30,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(128,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(129,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(134,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/focus-trap/focus-trap.d.ts(135,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/key-manager/list-key-manager.d.ts(96,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/key-manager/list-key-manager.d.ts(98,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/live-announcer/live-announcer.d.ts(69,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/a11y/live-announcer/live-announcer.d.ts(70,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/observers/observe-content.d.ts(62,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/observers/observe-content.d.ts(63,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/observers/observe-content.d.ts(66,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/@angular/cdk/observers/observe-content.d.ts(67,9): error TS1086: An accessor cannot be declared in an ambient context.
这是我的package.json
"name": "football",
"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/cdk": "^9.0.0",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/material": "8.2.3",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"hammerjs": "^2.0.8",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"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/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.5.3"
}
}
根据您的package.json,您使用的是Angular 8.3,但您已经导入了Angular/cdk v9。您可以降级angular/cdk版本,也可以通过运行以下命令将angular版本升级到v9:
ng update@angular/core@angular/cli
这会将您的本地角度版本更新为9。然后,为了同步材质,运行:
ng update@angular/material
首先请检查module.ts
文件,在@NgModule
中,所有属性仅为一次。
如果其中任何一个都不止一次,那么这个错误也会出现。
因为我也发生了这个错误,但是在module.ts
文件entryComponents
属性中发生了两次,这就是为什么我会出现这个错误。
我通过从@NgModule
中删除一次entryComponents
解决了这个错误。
因此,我建议您首先正确地检查它。在
编译器选项中添加skipLibCheck:true
在tsconfig.json
文件中修复了我的问题
"compilerOptions": {
"skipLibCheck": true,
},
这些问题通常是由于@ngx translate/core版本和Angular之间的不匹配而产生的。在安装相应ngx\u trnalsate/core之前,请检查兼容版本、@ngx translate/http loader和Angular at
例如:对于角度6.X版本
npm install @ngx-translate/core@10 @ngx-translate/http-loader@3 rxjs --save
和上面一样,遵循下面的命令,其余代码部分对于所有版本都是通用的(注意:版本可以从()获得)
我有这个问题,但我的package.json中没有版本冲突
我的package-lock.json与package-json不同步。删除并重新生成它对我有效。我通过以下步骤解决了同样的问题:
检查角度版本:使用命令:ng version我的角度版本是:angular CLI:7.3.10
之后,我通过链接获得了ngx引导的支持版本:
在package.json文件中更新版本:“bootstrap”:“^4.5.3”、“@ng bootstrap/ng bootstrap”:“^4.2.2”
现在,在更新package.json之后,使用命令npm update
在使用命令ng serve并解决我的错误后谢谢,我在安装angular flex时遇到了这个问题,angular flex自动安装了最新版本(在我的例子中是版本9)但是我在用angular 8。更正版本解决了问题issue@Kyler约翰逊:我怎么能沮丧呢/cdk@mdkamrul您可以通过运行npmi@angular来降级/core@8@棱角/cli@8@棱角/material@8
,假设您使用的是版本8。有时您的package.json和package-lock.json会与您的项目不同步将使用package-lock.json文件中的内容。因此,现在,运行npm i
来同步它们。如果在此之后仍然遇到问题,请运行npm ci
来完全干净地安装依赖项。我必须使用ng update@angular/cli@angular/core--force
,因为这些包本身不兼容,您可以否则不要切换。但是,跳过库检查不会在将来引起其他问题吗?谢谢@R15它对我有效,我正在使用angular 8You absolute legend。这很有效。我担心使用另一个更新typescript的修复程序,以防我的angular版本不兼容…它工作得很好…非常感谢为我节省时间
npm install @ngx-translate/core@version @ngx-translate/http-loader@version rxjs --save