Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TS1086: An accessor cannot be declared in ambient context in Angular 8 application using docker-compose

I have running "ng serve" locally in my angular 8 application everything works fine. But when I start running application using docker and docker compose getting the "An accessor cannot be declared in ambient context" error on @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.

Does somebody know a reason? I can't test my app until I fix it.

After enabled PWA in my angular 8 application facing the issue in docker-compose build. Normally when I am doing "ng serve" compilation success without any error.

Package.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"

I found some solutions to add skipLibCheck in tsconfig.json, I don't want to skip lib check.

"angularCompilerOptions": { 
      "skipLibCheck": true 
}

can somebody help me to resolve this. Thanks in advance.

like image 939
Sudhakar Chandrasekaran Avatar asked Nov 23 '25 20:11

Sudhakar Chandrasekaran


1 Answers

I can see your using version 8 of angular. ngx-scanner latest versions are not supporting angular 8.

There are two solutions:

  1. Update angular to version 12 to use the latest ngx-scanner version.
  2. Downgrade ngx-scanner to ~2.0.1
like image 62
Michael Winther Avatar answered Nov 25 '25 10:11

Michael Winther



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!