-
-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
issue with ts jest and node-fetch v3 #1289
Comments
This comment has been minimized.
This comment has been minimized.
ping @LinusU you have some more experiences with jest, maybe you have any suggestions? |
+1 same issue with ts/jest compiled with babel // jest.config.js option that might be relevant
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
}, |
Having the same problem here. |
i have same this problem! how fix this now ? Or need await solution ? |
@SashaJson we are currently migrating to axios since there are no responses to these quite challenging issues users are facing |
I experience the same issue on my side with swc and jest |
I think I made it work with "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch", jest.config.json if you are using ES Modules:{
"roots": ["<rootDir>/src"],
"extensionsToTreatAsEsm": [".ts"],
"testEnvironment": "node",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transform": {
"\\.[jt]sx?$": [
"babel-jest",
{
"babelrc": false,
"presets": ["@babel/preset-typescript"],
"plugins": ["@babel/plugin-proposal-optional-chaining"]
}
]
}
} Check you my example repository: https://github.com/lynxtaa/node-fetch-jest-example jest.config.json if you are using CommonJS:{
"roots": ["<rootDir>/src"],
"testEnvironment": "node",
"transform": {
"\\.[jt]sx?$": [
"babel-jest",
{
"babelrc": false,
"presets": ["@babel/preset-typescript"],
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-modules-commonjs"
]
}
]
}
} And in this case you should use dynamic import: const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); |
I have a few typescript projects where this happened to me. Add the following to transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js)$": "babel-jest",
},
transformIgnorePatterns: [
], Note the empty node-fetch: ^3.0.0 |
Rolling back to 2.6 worked for me to get serverless-bundle to run jest tests. |
Has anyone made any progress on this? I tried @lynxtaa's solution with no success. |
Same here, rolling back to 2.6 worked. Any of the other solutions were not working. |
same issue here, rolled back as well... |
rolling back worked as well! |
As typing information is already included in node-fetch 3.0 and up,
the @types/node-fetch package after version 3.0 is just a stub. To get
typing information you need to install a version of the types package
that's inside the 2.x range. In my case, I installed version 2.5.12 and
everything's working fine.
El lun, 10 ene 2022 a las 11:54, Bruno Mello ***@***.***>)
escribió:
… To those who are rolling back, how are you using the type definitions?
***@***.*** doesn't ship with type definitions and installing
@types/node-fetch doesn't seem to solve my problem.
Here is how I am importing the module
[image: image]
<https://user-images.githubusercontent.com/29875060/148814451-763c57a7-3d24-41e5-ad5d-7682db554f48.png>
And in my package.json I have listed both @types/node-fetch on
devDependencies and node-fetch on dependencies
{
...
"devDependencies": {
...
***@***.***/node-fetch": "^3.0.3",
...
},
"dependencies": {
...
"node-fetch": "^2.6.6",
...
}
}
—
Reply to this email directly, view it on GitHub
<#1289 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMYD4L4RSBSLIK2KKVL424TUVMMNXANCNFSM5D7Q2BZA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Is there a solution to using node-fetch 3.x with jest? |
Is there a solution for this? |
This is a small example where jest works with node-fetch@3: https://github.com/ravshansbox/jest-node-fetch-es-modules |
Note: edited after original comment this issue should be closed and reference #1279 End note
This is misleading as it works only because you are telling jest to run with support for ESM (--experimental-vm-modules). As far as I can tell, node-fetch v3 only works as an ESM and you cannot make it work in jest without that flag. Our teams are not going to use that flag unfortunately. So unless this becomes supported in Jest, we are going to use node-fetch <3.0.0 Also looks like it's slowing the adoption of node-fetch v3: |
I haven't played with jest lately... |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I upgraded node-fetch to v3, and run jest test and I get:
I followed instructions, but nothing changes,
I also tried this jest config
but nothing happens
The text was updated successfully, but these errors were encountered: