-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest attempts to transform my custom transform leading in "TypeError: Jest: a transform must export a process
function"
#7710
Comments
Do you use |
Yes, we are using |
Ok, yep, I was able to reproduce this: https://github.com/kentcdodds/jest-transform-self-transform-bug So the key here is that you have both So my guess is that #7562 solves this. Any ideas as to when that'll be released? I've not learned how to locally link a bunch of lerna packages so I'm not sure of the best way to test that current master solves the problem. But it does seem related. |
That PR has been released, that's what's causing your issue. 🙂 You need to include your setup or teardown in This should be documented somewhere, not sure where's the best fit, though |
Ooooh! I see 😅 Hmmm... Interesting. So it's just a limitation or something? I feel like this is something that jest should be able to detect and prevent? Maybe I'm misunderstanding what's going on though. When you mentioned I'd be willing to contribute the docs, though it's still unclear to me why this is happening and why it's not a bug that should be fixed instead 🤔 |
Not sure if it's functionally a bug, but we should definitely provide a better error. The real fix is to preload all transformers, and then install the |
Doing this should fix it, as it will make sure to load and cache the transformer before installing diff --git i/packages/jest-cli/src/runGlobalHook.js w/packages/jest-cli/src/runGlobalHook.js
index cd5a4ff06..4c6b3ed0d 100644
--- i/packages/jest-cli/src/runGlobalHook.js
+++ w/packages/jest-cli/src/runGlobalHook.js
@@ -49,6 +49,10 @@ export default ({
const transformer = new Runtime.ScriptTransformer(projectConfig);
+ // Load the transformer to avoid a cycle where we need to load a
+ // transformer in order to transform it in the require hooks
+ transformer._getTransformer(modulePath);
+
const revertHook = addHook(
(code, filename) =>
transformer.transformSource(filename, code, false).code || code,
Of course, that calls a private API, so we should make a non-private one. But that should fix the issue. |
@kentcdodds, can you provide your final version of jest config please, because I've followed all instructions above and I'm still getting this error. 😕 |
This branch has the fix: https://github.com/kentcdodds/jest-transform-self-transform-bug/tree/context-issue Though there was a new bug in watch mode that this revealed as well (#7740) which has been fixed but not yet released. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Sorry, I'll add more details later. Just getting this down now so I don't forget what I've learned so far before I wrap up for the weekend.
🐛 Bug Report
I have a custom transform that uses
babel-jest
to create a transformer based on a certain babel config that does not exist in the typical place (this is for a toolkit where the config resides inside a package, not in the project).To Reproduce
Steps to reproduce the behavior:
I'll create a reproduction repo next week.
Expected behavior
In
jest-runtime/build/ScriptTransformer.js
in_getTransformer
I'm getting:Adding some console logs around shows me that it goes through that function twice with the same file (my custom transform). Here's an outline of where the code gets to:
This is pretty unusual I think. It's not entirely clear to me why the
_getTransform
function is getting called twice, but my assumption is that Jest is attempting to transform the transform file. Efforts to configure jest to ignore the transform file failed so I'm missing something else.Link to repl or repo (highly encouraged)
I'll try to add something next week.
Run
npx envinfo --preset jest
Paste the results here:
Thanks! Looking forward to upgrading!
The text was updated successfully, but these errors were encountered: