-
Notifications
You must be signed in to change notification settings - Fork 133
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
Error when using with NestJS #113
Comments
I'm not sure how to reproduce the issue.
How have you installed node-fetch? You'll need to register the polyfill to the global context. I recommend https://github.com/lquixada/cross-fetch: // npm install cross-fetch --save
require('cross-fetch/polyfill'); This and other older node version caveats you can find in https://github.com/pocketbase/js-sdk#nodejs-via-npm. |
this is exactly what I did:
however when i run this, i get this error in the console.
now, if i replace import
so |
Ah, I now remember that there was a similar nest issue (#52). Nestjs doesn't currently support out of the box ESM (or at least the last time I checked). |
I've done all those workarounds, but I'm still getting |
@mandrillxx How you are loading the polyfill? As mentioned previously you need to load it in the global context, aka. require('cross-fetch/polyfill');
// or
import 'cross-fetch/polyfill'; You don't need a polyfill if you upgrade to node17+.
I don't understand what do you mean. The JS SDK is ES module. We have also a fallback for CJS. The types highly depends on your TS config and I'm not sure how to help you without any information on what node and ts versions you are using and what is your ts config. |
I'm going to use it without types and with require, it's too messy otherwise. What I mean though is that this module doesn't just work out of the box like many others, at least with nestjs. |
@mandrillxx I'm not really sure how to explain it better. First, you don't need a polyfill if you upgrade to Node 17+. Second, this is not an issue with the SDK, but with Nest not supporting ESM out of the box (see nestjs/nest#10267 (comment), nestjs/nest#8736 and probably others). When you use If I apply locally the 3 changes suggested in #52 (comment), it works fine for me. Another workaround is the suggestion in #52 (comment). You've written that you've tried all of the above but there is not enough information to help you debug it. If you provide a minimal reproducible repo with what you've tried, I'll have a look at it, but by just saying "it doesn't work" I don't know how to help. |
Firstly, I can't import using
because of this similar issue: #34 so I'm using
which doesn't provide types.
Now, I'm getting this error.
I've installed node-fetch but this is still the error I get. Is there a solution?
The text was updated successfully, but these errors were encountered: