grammyjs / types

Type declarations of the Telegram Bot API.
MIT License
38 stars 5 forks source link

`@grammyjs/types doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" in package.json or an .mjs extension for the entry point)` #23

Closed ni554n closed 1 year ago

ni554n commented 1 year ago

Version: 3.0.3

I'm getting this warning in an Astro project that uses Vite under the hood.

I think the solution might be to add an empty export to the mod.js file so that it can be detected as Common JS module in Vite.

KnorpelSenf commented 1 year ago

Can you share how to reproduce this?

ni554n commented 1 year ago

https://stackblitz.com/edit/node-vbcbrq?file=tsconfig.json,src/pages/grammyTypes.ts,src/pages/index.astro

KnorpelSenf commented 1 year ago

I don't really see how this can be fixed. This package is meant to be empty, it contains 0 bytes of executable code. There is nothing wrong here, so there is nothing that we can do to fix it.

It seems like Astro seems to assume that such packages are invalid. IMO this assumption is incorrect. Perhaps you should open an issue for Astro and tell them that this warning is reported incorrectly. Perhaps there is a way to suppress such warnings.

I will close this now as there is nothing to do here. Please comment if the astro authors disagree and can come up with any ideas that can be improved about this repo.

ni554n commented 1 year ago

Thanks for looking into it.

I searched around a bit on GitHub issues and found out it's a Vite thing. The solution is very simple though. Just adding // module.exports (as a comment) in the mod.js file makes the warning go away. 😅

KnorpelSenf commented 1 year ago

Oh wow. Feel free to open a pull request that adds such a comment to mod.ts if that helps :)

ni554n commented 1 year ago

@KnorpelSenf Hi, I just checked the latest release of this package, and the comments are not present in the mod.js file. Aren't they supposed to be there if not explicitly disabled using https://www.typescriptlang.org/tsconfig#removeComments ?

KnorpelSenf commented 1 year ago

@wojpawlik?

wojpawlik commented 1 year ago

Looks like a TypeScript bug. deno2node forces the option off.

ni554n commented 1 year ago

Maybe setting that option explicitly in this project's tsconfig would do the trick!?

wojpawlik commented 1 year ago

That'd change nothing. What about adding export {} to mod.ts?

KnorpelSenf commented 1 year ago

We'd have to experiment with this. Why are JSDoc string kept but // comments stripped? Or did I misunderstand?

ni554n commented 1 year ago

@KnorpelSenf I'm not sure how to experiment with this package. I've never used deno in a local environment. Can you please write a build instruction?

KnorpelSenf commented 1 year ago

Yes, I should add that to the README, you're right.

Just run npm install in the top level directory of this repo. That will download all deps and compile the code. Run npm run prepare to recompile.

It's easier to install Deno tooling. There's a VSCode extension for Deno. Run deno task to see available tasks, and run deno task backport to compile. In fact, that's what npm uses under the hood, too.

KnorpelSenf commented 1 year ago

I found the problem. Please review #26.

KnorpelSenf commented 1 year ago

Update your deps and it will be fixed

ni554n commented 1 year ago

Yes! Just tested it. No more warning! Thanks a lot.