Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with CommonJS. #447

Closed
mits87 opened this issue Nov 14, 2024 · 7 comments · Fixed by #448
Closed

Problem with CommonJS. #447

mits87 opened this issue Nov 14, 2024 · 7 comments · Fixed by #448
Labels
bug Something isn't working

Comments

@mits87
Copy link

mits87 commented Nov 14, 2024

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
Copy link
Owner

schoero commented Nov 14, 2024

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

@mits87
Copy link
Author

mits87 commented Nov 15, 2024

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 schoero added the bug Something isn't working label Nov 15, 2024
@schoero
Copy link
Owner

schoero commented Nov 19, 2024

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

@schoero schoero removed the bug Something isn't working label Nov 19, 2024
@hohler
Copy link

hohler commented Nov 21, 2024

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 🙏

@mits87
Copy link
Author

mits87 commented Nov 28, 2024

hi I made very simple example here:
https://stackblitz.com/edit/nestjs-typescript-starter-mtaweg?file=src%2Fapp.controller.ts

As you can see we have problem with import the library:
image

@schoero schoero added the bug Something isn't working label Dec 7, 2024
@schoero
Copy link
Owner

schoero commented Dec 7, 2024

It seems that there are indeed some things wrong with the package.json. There also seem to be some problems with the type exports.

As a temporary workaround, I have updated the main field in the package.json to reference the bundle in version 4.1.1-beta.0. You should now be able to import it in the beta version as follows:

import SwissQRBill from 'swissqrbill';

Resolving the underlying issues will require a more in-depth investigation. I should have time to look into it in the next 2–3 weeks.

@schoero
Copy link
Owner

schoero commented Jan 1, 2025

I just published v4.1.1 on npm. The exports now have been fixed and should work with moduleResolution: node10. If you upgrade, your repro works without further changes.

Also publint and are the types wrong no longer report any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants