tuananh / camaro

camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
MIT License
556 stars 29 forks source link

Type declarations might not be properly referenced #148

Closed ghost closed 2 months ago

ghost commented 2 months ago

Describe the bug When trying to use the library in a TypeScript app, I'm getting the following error from VSCode :

Could not find a declaration file for module 'camaro'. 'app_path/node_modules/.pnpm/camaro@6.2.3/node_modules/camaro/index.mjs' implicitly has an 'any' type.
There are types at 'app_path/node_modules/camaro/index.d.ts', but this result could not be resolved when respecting package.json \"exports\". The 'camaro' library may need to update its package.json or typings.

Minimal Script To Reproduce Install camaro with pnpm, then simply import the library in a ts file.

import { transform } from "camaro";

Expected behavior Type declarations to be properly taken in account.

tuananh commented 2 months ago

This typings is added by a contributor. I'm not a TypeScript user myself so if you know how to fix it, I will happily merge the PR

ghost commented 2 months ago

Ok so, after doing some searching, I found this only throws an error when using strict mode for TypeScript. Then I found two ways of solving this :

  1. I was using "type":"module" in my app's package.json, removing it removed the error. I was using it from a previous similar app but removing it did not affect things much. 👍
  2. In case "type":"module" is necessary for you, find /node_modules/camaro/package.json and change "import": "./index.mjs" to "import": "./index.js" - that did not break anything for me and removed the error completely too.

Not sure this is worth a PR @tuananh, as this should rarely ever happen to anyone and if it ever does, it's a very simple fix. I'm also worried it might break some projects that need the mjs extension for imports.

Cheers.