-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
@remix-run/web-fetch
causes tests to error after upgrade to jest 28
#3402
Comments
@remix-run/web-fetch
distributed types point to missing files
@penx You can always create a PR to https://github.com/remix-run/web-std-io if you want. |
On closer inspection, vscode's ts server seems to be able to resolve |
@penx Would be nice if we could find the root cause. |
I'm looking 😄 if I can't figure it out soon I may need to look again later in the week. My understanding is Jest is configured to use Babel to compile the TS, which is reporting the TypeError due to not being able to resolve the type via the sourcemap, wheras TypeScript manages to do this. edit: having said that, I don't think Babel checks types... I haven't yet found any issues on babel referencing this. I am wondering whether ts-jest has been considered? |
I haven't completely traced the source of the issue but it seems changing ".": {
"browser": "./src/lib.js",
"require": "./dist/lib.node.cjs",
"import": "./src/lib.node.js",
"types": "./dist/src/lib.node.d.ts"
}, to ".": {
"require": "./dist/lib.node.cjs",
"import": "./src/lib.node.js",
"types": "./dist/src/lib.node.d.ts",
"browser": "./src/lib.js"
}, ...in the @remix-run/web-fetch package.json seems to resolve this issue. There are continued Jest issues after this though so I'll try to keep digging. |
Ok I have transformIgnorePatterns: [
"/node_modules/(?!(@remix-run/web-fetch|@remix-run/web-blob|@remix-run/web-stream|@remix-run/web-form-data|@remix-run/web-file|@web3-storage/multipart-parser)/)",
], I was going to suggest the above change anyway as it the exports order is important and I don't understand why the browser export would appear first (or why it would point to the source) so can raise a PR for that. |
Exports are resolved in order, i.e. the first match is used. I'm not sure why the browser export is using the raw src, however this causes issues with Jest when configured with jsdom, as it will resolve to this file and not be able to transpile it. Jest also throws a type error as discussed on remix-run/remix#3402
Exports are resolved in order, i.e. the first match is used. I'm not sure why the browser export is using the raw src, however this causes issues with Jest when configured with jsdom, as it will resolve to this file and not be able to transpile it. Jest also throws a type error as discussed on remix-run/remix#3402
Exports are resolved in order, i.e. the first match is used. I'm not sure why the browser export is using the raw src, however this causes issues with Jest when configured with jsdom, as it will resolve to this file and not be able to transpile it. Jest also throws a type error as discussed on remix-run/remix#3402
Read something about Community Conditions Definitions today (can't remember where though 😅), which says https://nodejs.org/api/packages.html#community-conditions-definitions |
@remix-run/web-fetch
distributed types point to missing files@remix-run/web-fetch
exports result in error from tests after upgrade to jest 28
@remix-run/web-fetch
exports result in error from tests after upgrade to jest 28@remix-run/web-fetch
causes tests to error after upgrade to jest 28
Changing the order to "types": "./dist/src/lib.node.d.ts",
"browser": "./src/lib.js",
"require": "./dist/lib.node.cjs",
"import": "./src/lib.node.js" Still results in the same issue, though "types": "./dist/src/lib.node.d.ts",
"require": "./dist/lib.node.cjs",
"import": "./src/lib.node.js",
"browser": "./src/lib.js" It is fixed as before. I'd read about the types export recently too - I'll update my PR to do that. |
@penx Yeah I think you referenced it somewhere. |
https://nodejs.org/api/packages.html Not sure if this is what you mean you couldn't find as that's what you just linked to :-) |
@penx I meant the thing you referenced that was referencing Community Conditions Definitions. |
@penx It was mentioned in GoogleCloudPlatform/functions-framework-nodejs#461 (comment). Do we still need the update |
Ah ok, I was about to link to these which I've been looking at over last couple days |
yes I am pretty sure the jest update is still needed so that it can resolve import { getTestServer } from "@google-cloud/functions-framework/testing"; From what I remember, before Jest 28, Jest won't look for exports defined in package.json |
Although I'm not sure why GoogleCloudPlatform/functions-framework-nodejs#461 is needed - when the |
I was able to get most tests working following this thread, but I still cannot get a simple fetch request to pass. I always get this error:
I'm transforming these files within jest:
Here is my fetch request:
Once I import this into the test and try to run it - I get that error. Here is my repo: |
@penx is this still a problem for you? |
This was preventing the upgrade from Jest 27 to 28+ Remix is still using Jest 27 and the upstream PR I raised to resolve this has not been merged, so I am pretty sure it is still an issue. |
For what it's worth, we're running into this exact same issue and had to downgrade to Jest 27. I guess we're blocked until Remix upgrades to Jest 28?
Our Jest config:
|
We ran into the same problem when attempting to upgrade to Jest 28 (or Jest 29 for that matter). I have not tested the fix in remix-run/web-std-io#11 but that seems like a simple fix to unblock those of us who would like to upgrade Jest. |
The actual fix wouldn't be remix-run/web-std-io#11, but remix-run/web-std-io#43 instead |
What version of Remix are you using?
1.5.1
Steps to Reproduce
jest
-related dependencies to v28 #3400jest
-related dependencies to v28 #3400 (comment)yarn test:primary
Expected Behavior
Tests should pass
Actual Behavior
This seems to relate to the types output by
@remix-run/web-fetch
:node_modules/@remix-run/web-fetch/dist/src/lib.node.d.ts
fetch.js and package.js do not exist in the distributed
@remix-run/web-fetch
and should either be included or lib.node.d.ts should be pointing tofetch.d.ts
andpackage.d.ts
The text was updated successfully, but these errors were encountered: