Library: Cannot compile libary code.

Created on 14 Mar 2020  路  12Comments  路  Source: zxing-js/library

No one else is reporting this issue, so I must be doing something wrong. But, I have not been able to figure out what. I installed the library into my solution per instructions. But, 'BigInt' is not recognized. I researched this and learned 'BigInt' was implemented in TypeScript 3.2. From my package.json file: "typescript": "~3.7.5"
The original TypeScript 3.2 documentation states that you must target esnext, so I changed my tsconfig to: "target": "ESNext", though it was originally set to a later version. So, I think that should've been good. I am unclear on the requirements of the module configuration. I tried ESNext, but that didn't work. I looked at the tsconfig for this library, and it was CommonJS, so I changed it to: "module": "CommonJS". But, nothing seems to make it work.

So, I downloaded the library by itself, opened the solution, ran npm install to install the required libraries, and I still get a tsc compilation error on BigInt. This is only from compiling the source code "as is". Can someone tell me what I'm doing wrong. Errors are below:

C:\Solutions\ZXingScannerLibary>tsc
src/core/pdf417/decoder/DecodedBitStreamParser.ts(51,23): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(55,15): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(57,21): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(116,36): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(613,55): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(613,72): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(667,51): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(667,68): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(773,17): error TS2304: Cannot find name 'bigint'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(773,26): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(775,17): error TS2304: Cannot find name 'BigInt'.
src/core/pdf417/decoder/DecodedBitStreamParser.ts(775,72): error TS2304: Cannot find name 'BigInt'.

C:\Solutions\ZXingScannerLibary>

Most helpful comment

Yeah, I finally drop the .d.ts file using and switched to a more "secure" way of doing this, I just had to import the typings in every file, but (for now) that's ok and we can move on. Maybe someday I'll go back to this, since the easiest it is coping code from Java, the easy it is for new contributors to help.

All 12 comments

I've my project with Angular8, on 'ng serve --aot' I'm getting the following errors: ../node_modules/@zxing/library/esm/core/common/BitMatrix.d.ts:137:17 - error TS2304: Cannot find name 'int'.

137 hashCode(): int;
~~~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:10:20 - error TS2304: Cannot find name 'float'.

10 constructor(x: float, y: float);
~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:10:30 - error TS2304: Cannot find name 'float'.

10 constructor(x: float, y: float);
~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:11:13 - error TS2304: Cannot find name 'float'.

11 getX(): float;
~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:12:13 - error TS2304: Cannot find name 'float'.

12 getY(): float;
~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:14:17 - error TS2304: Cannot find name 'int'.

14 hashCode(): int;
~~~
../node_modules/@zxing/library/esm/core/ResultPoint.d.ts:28:68 - error TS2304: Cannot find name 'float'.

28 static distance(pattern1: ResultPoint, pattern2: ResultPoint): float;
~
../node_modules/@zxing/library/esm/core/common/StringUtils.d.ts:40:54 - error TS2304: Cannot find name 'int'.

40 static getCharCode(str: string, index?: number): int;

I could see in my node_module folder the compiled code for ZXing there's not typyings.d.ts (where you guys have declared all these 'int', 'float' etc.)

I have exactly the same issue as @praveensoni1803 in angular 9.

Just to know, why on earth are you trying to compile the library's code inside an Angular project?

I think @praveensoni1803 error and mine are different from @spazjr01

Our errors are shown after compiling our respectives angular apps.
I just installed it with npm i @zxing/library --save and used it like shown in the README.md.
Everything is working just fine exept for these error shpowing in the terminal after building the angular app. It's like typescript does not find the definition for "float" and "int"

@xLeDocteurx As I mentioned this file typyings.d.ts has all the definition required and I was in a hurry so I just replaced the "float" and "int" with "number" in compiled code for now, It's working fine now.

@odahcam , I'm not compiling the code I just did npm i @zxing/library --save and the I did ng serve --aot, which is required to run my project locally right?

Fixed the problem going back to previous release

Editing my package.json this way, and running npm install again :

    "@zxing/library": "^0.15.2",

Or on a new project you can install it this way :

npm i @zxing/[email protected] --save

Now I'm pretty sure my CTO wont kill me.
Thanks @odahcam for you awesome work on this library and the cool releases names you make !

I hope you will have a lot of issues for this year Hacktober fest. I will be back at this moment.

Edit. Typing.d.ts is in github repo but not on npm.
It's like it is npm ignored. But it is not in the .npmignore file

I ended up solving this (the original problem at the beginning of this post) by doing the following.

  1. I migrated the source code to my project.
  2. I ran 'npm install big-integer' to install a library that handles BigInt[]
  3. I added the following statement to handle the other BigInt() references:
    declare var BigInt: any;

I had to make other changes to make this work in my angular/ionic solution. I now have a pdf417 scanning solution that works (with autofocus and light controls) in an angular/ionic solution.

Good point @xLeDocteurx, thanks for finding that out.

I'm not pretty sure what you did was the best possible way to follow, but I'm happy you found a solution @spazjr01!

@odahcam
I recently had to update an angular 6 app to angular 9 and found something interesting in the doc wich seems related to the issue :
https://update.angular.io/#6.1:9.0l3

" We have updated the tsconfig.app.json to limit the files compiled. If you rely on other files being included in the compilation, such as a typings.d.ts file, you need to manually add it to the compilation."

Yeah, I finally drop the .d.ts file using and switched to a more "secure" way of doing this, I just had to import the typings in every file, but (for now) that's ok and we can move on. Maybe someday I'll go back to this, since the easiest it is coping code from Java, the easy it is for new contributors to help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hopingocean picture Hopingocean  路  3Comments

sethusuryateja picture sethusuryateja  路  6Comments

memic84 picture memic84  路  10Comments

kenlyon picture kenlyon  路  6Comments

jsid72 picture jsid72  路  6Comments