alexandercerutti / passkit-generator

The easiest way to generate custom Apple Wallet passes in Node.js
MIT License
897 stars 109 forks source link

TypeScript import fails unless 'esModuleInterop' is set to true #125

Closed mortenbekditlevsen closed 1 year ago

mortenbekditlevsen commented 1 year ago

Running OS

macOS Monterey

Running Node Version

16

Description

Hi @alexandercerutti , Thank you for an amazing library - and excellent documentation. This has enabled me to get up and running with server side pass generation in a few hours.

I wouldn't exactly call myself an expert in TypeScript, but the import statements in the schemas (like in Barcode.d.ts) are in the form of:

import Joi from "joi";

This gives me an error unless I set esModuleInterop: true in my tsconfig.json. But this option unfortunately clashes with other libraries I am including.

I tried replacing the import statements with:

import * as Joi from "joi";

and this solves my issue without requiring esModuleInterop.

Would you accept a PR that changes the import statements?

As mentioned, I'm not a TS expert, so I don't know if the change could have any negative side effects.

alexandercerutti commented 1 year ago

Hey @mortenbekditlevsen, thanks for using passkit-generator!

Just for you to know, esModuleInterop is a flag that is better to have active. The reason is that when TS folks tried to implement the support to ESM, they introduced a behavior that was not expected from the standard (or, sort of...).

You can see more here: https://www.typescriptlang.org/tsconfig#esModuleInterop and https://stackoverflow.com/questions/56238356/understanding-esmoduleinterop-in-tsconfig-file

Let me add, also, that this module is still a CJS module. I think I'll move it to ESM with the next major.

So, I'm honestly a bit reluctant to change this. It probably doesn't make any difference, but I have to see more deeply and make some tests.

I don't know which other libraries are giving you issues, but maybe there's a different way to solve the issue for them.

Let me know!

mortenbekditlevsen commented 1 year ago

Hi @alexandercerutti , Thank you for your thorough reply! I'll have a look at my other dependencies and see if I can make them work with esModuleInterop for now. :-)