schoero / swissqrbill

Swiss QR Bill generation in Node.js and browsers
MIT License
163 stars 29 forks source link

Problem with CommonJS. #447

Open mits87 opened 1 week ago

mits87 commented 1 week ago

Hi, first of all thank you for really great library.

There is one small problem, basically I can't use this library in project with CJS (example NestJS). Whenever I'm trying to import the library I'm getting:

Cannot find module 'swissqrbill/pdf' or its corresponding type declarations.
Cannot find module 'swissqrbill/utils' or its corresponding type declarations.

Can you help me with that?

schoero commented 1 week ago

Can you change moduleResolution in your tsconfig.json to "bundler", "node16", or "nodenext"?

mits87 commented 1 week ago

Hi @schoero, this was my first thought but I can't change it because my NestJs application stop working. The "module" must stay as "commonjs" otherwise everything stop working.

image

Also I tried to import it like: import { SwissQRBill } from 'swissqrbill/lib/cjs/pdf';

But then I have problem with:

image

Would you mind to provide some workaround?

schoero commented 5 days ago

I tried to reproduce this, but It seems to work also with "module": "CommonJS" and "moduleResolution": "classic".

Take a look here: https://stackblitz.com/edit/schoero-swissqrbill-bpener?file=src%2Fpdf.ts

hohler commented 3 days ago

According to https://www.typescriptlang.org/tsconfig/#moduleResolution - classic shouldn't be used anymore.

In my case, an Angular 18 project would not build with CommonJS/classic settings.

Saying this, I have a similar problem, just that another library does not support moduleResolution: Bundler (also not in connection with "type": "module" in the package.json).

But it's probably easier to find a workaround in my case.

Anyways, thank you very much for building and maintaining this library 🙏