-
Notifications
You must be signed in to change notification settings - Fork 21
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
possible to not require ESM ? #11
Comments
common issue with node-fetch |
Hey @dcsan , thanks for taking the time to post some feedback! I do agree that Typescript would offer a better development experience for maintainers and consumers of the library. But, I've put off Typescript because it requires additional build and test tooling, which feels like overkill for ~100 lines of code. And it has some implications for the portability of the library. And I'm no Typescript expert. Do you think that JSDoc typing information for public methods might be a good first step to improve the development experience for consumers of the library? Here's an article that summarizes how that works and that mostly aligns with my opinion: https://blog.logrocket.com/typescript-vs-jsdoc-javascript/. But the bigger issue is this library clashing with Typescript's support for ESM. What version of Typescript does your project use? And is there anything that is preventing you from using TypeScript 4.7+? |
tx for the response! and the nice and understandable code base! i found typescript makes it easy to build packages when i've used it, and then you have a typings file created too. One thing I hit right away on using this plugin was a "no typings" warning, and I guess none exist. So I had to wrap all calls with i understand the risk is it might put off people contributing, but if you set everything up, it's not a big deal to just edit / build. JSDoc is a bit of a band-aid approach imho. It's always half worked for me and depends on the editor having the right intellisense plugins installed. using typescript would fix this properly. yes, the bigger issue is as soon as I add all imports now need to have typescript by default always uses some of the problems created in dependent libraries are more baffling: so if it was possible to switch to 2.6 of node-fetch or use axios or a less requiring of going cold turkey ESM to do requests it would be easier to adopt this package into a typescript app. I did actually try axios but had some problems with unpacking the binary data, so just switched to an older node-fetch. It's probably something we could figure out. |
I believe we can use node-fetch@2, or switch to axios/cross-fetch. What do you think @nicholascelestin? |
Sorry for the late response to this @dcsan -- I do appreciate the effort you put into your response. I just moved and that took up a lot of bandwidth for a couple of weeks. Hmmm, are you saying that installing an older version of node fetch fixed the problem and that you didn't need to make any changes to the library itself in order to get it to work? And @vastamaki, is that what you're suggesting as well? If so, a quick way to resolve this issue (ahead of a full-on typescript rewrite) might be to add that proviso to the readme. My limited understanding of ESM in modern Typescript (4.7+) is that there is interoperability such that you don't need to modify your whole project to use pure ESM. I think you can configure your compiler options like this: https://www.typescriptlang.org/docs/handbook/esm-node.html#type-in-packagejson-and-new-extensions But I'm not 100%. Could you provide a bit of code that reproduces the issue you're having, so I can learn some about TS, fiddle with it, and see what's up? |
not quite. the older versions of fetch I have used on other projects, as it didn't require porting everything to ESM. I didn't try to use that version with your package as yet.
yes I started on that process, but hit various snags, such as in other dependent libraries like sequelize-typescript. there really is no benefit to ESM i can see if you're already using typescript, and a LOT of problems and refactoring is required. also adding a clunky |
Please add something. I've been banging my head against this for hours lol. Edit: |
I think there's another package for replicate that isn't ESM based, you could ask in the discord. |
Since NodeJS 18.13.0 is now LTS, supported by AWS and other major cloud platforms, and has a built-in fetch module, I believe we could use that instead of node-fetch in case the node version is >=18. I believe that would make things a bit simpler at least when using the latest NodeJS versions. |
UPDATE: **Fixed! Solution:
Ref: zebreus/replicate-api#1** -- Hey guys, same problems here :). Any ideas how to overcome? I think I tried everything...
I guess those settings are incorrect. Before I tried to use the lib, my settings were like that (and the app was working ok):
|
I have a huge project and always hit problems trying to use "pure" ESM. Mainly because I'm using typescript, which just doesn't seem to work well with ESM...
I know the node-fetch guys want to force ESM but the older versions "node-fetch": "2.6.1", work fine.
one thing that would be nice for this package is proper type definitions, which you get for free if you wrote it in typescript?
any thoughts?
I've been wading thru my project for an hour already and have another
Found 967 errors in 262 files.
... to do with various import problems. some other broken packages eg sequelize-typescript use TS meta magic that's out of my depth to fix, at which point I gave up.For importing raw binary data eg from the Dalle-min model I found the node-fetch library did a good job. I was planning to throw it out and use axios or another lib, but found it easier to just use node-fetch older version.
The text was updated successfully, but these errors were encountered: