maugenst / tabletojson

An npm module for node.js to convert HTML tables to JSON objects
https://www.npmjs.com/package/tabletojson
MIT License
138 stars 38 forks source link

Improve operatibility with latest module systems #85

Closed mukulgupta21 closed 11 months ago

mukulgupta21 commented 11 months ago

Background context: I was trying to use tablejson inside my project which uses the moduleResolution as nodenext and the package complained with typescript errors. On investigation, I found out that @types/cheerio was no longer needed with the latest cheerio package as it supplied its own types. Adding the .js extension while importing modules, although unintuitive, is a more future proof way while maintaining backward compatibility.

Let me know if this can be included.

maugenst commented 11 months ago

I'm currently preparing a hybrid package that can cope with the needs of both worlds. I'll add this to master in the next few days. Thanks for your PR. I'll leave it open and let you check the changes.

maugenst commented 11 months ago

Hi.

I published version 4.0.0 which should be able to copy with the need of both worlds. Could you please give this a shot and get back to me in any case of an error.

Thanks

mukulgupta21 commented 11 months ago

I tried using the latest version got the folllowing error.

error TS7016: Could not find a declaration file for module 'tabletojson'. '/working-directory/tabletojson/dist/lib/mjs/Tabletojson.js' implicitly has an 'any' type.
  There are types at '/my-project/node_modules/tabletojson/@typings/Tabletojson.d.ts', but this result could not be resolved when respecting package.json "exports". The 'tabletojson' library may need to update its package.json or typings.

1 import { Tabletojson as tabletojson } from 'tabletojson';

Can you please check?

maugenst commented 11 months ago

Like displayed in the issue here: https://stackoverflow.com/questions/58211880/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-import I would like to ask you to create a small project I can fork which has the problems. It is clear, that typingsand typesare equivalent and can both be used.

I tested it in a test project I created, everything worked.

But as far as I see this is a problem which is not as easy to be solved: https://github.com/microsoft/TypeScript/issues/52363#issuecomment-1659227177 and https://gist.github.com/andrewbranch/79f872a8b9f0507c9c5f2641cfb3efa6

So, as far as I can see, the problem is the module resolution with nodenext. For now I cannot see a solution for this behavior despite the fact that I would have to create a second library for nodenext.

mukulgupta21 commented 11 months ago

Thanks @maugenst for reverting back. Here is a link to a toy project. Simply run npm run compile to reproduce the issue.

maugenst commented 11 months ago

I'll have a look and get back to you...

maugenst commented 11 months ago

With version 4.0.1 I changed the type exports. I tested it with your project and it worked. Could you please verify?

mukulgupta21 commented 11 months ago

Thank you. It works with my project. Appreciate your prompt response! Strange that "types" and "typings" are not synonymous as claimed by the documentation. Must be a tsc bug with nodenext resolution. I'll close the pull request.