node.js - TS1086:无法使用 docker-compose 在 Angular 8 应用程序的环境上下文中声明访问器
问题描述
我在我的 Angular 8 应用程序中本地运行“ng serve”,一切正常。但是,当我开始使用 docker 和 docker compose 运行应用程序时, @zxing/ngx-scanner上出现“无法在环境上下文中声明访问器”错误
| ERROR in ../node_modules/@zxing/ngx-scanner/lib/browser-multi-format-continuous-reader.d.ts:12:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 12 get isTorchAvailable(): Observable;
| ~~~~~~~~~~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:104:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 104 get codeReader(): BrowserMultiFormatContinuousReader;
| ~~~~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:108:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 108 set device(device: MediaDeviceInfo | null);
| ~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:116:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 116 get device(): MediaDeviceInfo | null;
| ~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:120:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 120 get formats(): BarcodeFormat[];
| ~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:126:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 126 set formats(input: BarcodeFormat[]);
| ~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:130:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 130 get hints(): Map<DecodeHintType, any>;
| ~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:134:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 134 set hints(hints: Map<DecodeHintType, any>);
| ~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:138:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 138 set isAutostarting(state: boolean | null);
| ~~~~~~~~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:142:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 142 get isAutostarting(): boolean | null;
| ~~~~~~~~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:146:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 146 set torch(on: boolean);
| ~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:150:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 150 set enable(enabled: boolean);
| ~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:154:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 154 get enabled(): boolean;
| ~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:158:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 158 get tryHarder(): boolean;
| ~~~~~~~~~
| ../node_modules/@zxing/ngx-scanner/lib/zxing-scanner.component.d.ts:162:9 - error TS1086: An accessor cannot be declared in an ambient context.
|
| 162 set tryHarder(enable: boolean);
| ~~~~~~~~~
|
| ** Angular Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **
| ℹ 「wdm」: Failed to compile.
有人知道原因吗?在我修复它之前,我无法测试我的应用程序。
在我的 Angular 8 应用程序中启用 PWA 后,面临 docker-compose build 中的问题。通常当我做“ng serve”编译成功时没有任何错误。
包.json:
"@angular/animations": "^8.2.14",
"@angular/cdk": "^8.2.3",
"@angular/common": "^8.2.14",
"@angular/compiler": "^8.2.14",
"@angular/core": "^8.2.14",
"@angular/flex-layout": "^7.0.0-beta.23",
"@angular/forms": "^8.2.14",
"@angular/material": "^7.3.2",
"@angular/platform-browser": "^8.2.14",
"@angular/platform-browser-dynamic": "^8.2.14",
"@angular/router": "^8.2.14",
"@zxing/ngx-scanner": "3.0.0"
我找到了一些在 tsconfig.json 中添加 skipLibCheck 的解决方案,我不想跳过 lib 检查。
"angularCompilerOptions": {
"skipLibCheck": true
}
有人可以帮我解决这个问题。提前致谢。
解决方案
我可以看到您使用 Angular 的第 8 版。ngx-scanner 最新版本不支持 Angular 8。
有两种解决方案:
- 将 angular 更新到版本 12 以使用最新的 ngx-scanner 版本。
- 将 ngx-scanner 降级到 ~2.0.1
推荐阅读
- c# - 为什么Identity的UserManager不能识别配置方法中的Create方法?
- ocaml - OCaml:如何安装漂亮的打印机并在代码中使用它?
- java - JPOS 何时禁用、释放和关闭打印机
- python - Pandas df.at() 引发 AttributeError:“BlockManager”对象没有属性“T”
- python - 使用python库googlemaps在google geolocation api中使用邮政编码查找位置坐标
- typescript - 无法将 pixi.js 导入 .ts 文件
- react-native - 使用标头中的令牌响应本机 Get 请求
- angular - (Angular 2/4/5/6) 订阅服务后从服务器获取错误响应
- python - 了解前馈神经网络输出
- reactjs - 为什么每当父状态发生变化时,组件更新生命周期就会执行?