-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 "SyntaxError: Cannot use import statement outside a module" when using node-fetch in Jest with Typescript #1588
Comments
I solved this - it was not an issue with node-fetch, apoligies. See here if you need the solution. |
I don't think this has been resolved. It's still happening to me. I don't think the solution is to downgrade the library to the 2.x version. We will need to upgrade at any moment, which will continue to fail. Is there any solution to get this working with 3.x version? |
An alternative method is switching to using NodeJS v18 \w built in fetch, FormData, and the rest. it's more spec compliant using web streams instead. |
@jimmywarting I didn't know that Node v18 comes with built-in fetch. I will consider switching instead of migrating to the 3.x version. However, thanks to your fantastic effort with this library. It helped me solve particular problems I was facing with other libraries. |
After a thorough search, I found the answer to my question |
I am trying to write an integration test in Typescript with Jest which uses node-fetch, like this:
But I am getting the following error:
I believe this is specifically a problem with
node-fetch
because it only affects imports from this package. For example, I can doimport express from 'express'
without any difficulty.Reproduction
Steps to reproduce the behavior:
temp.test.ts
:npx jest
Expected behavior
The test calls fetch
Your Environment
The text was updated successfully, but these errors were encountered: