-
-
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
"synchronous transformer must export a "process" function" when using processAsync
#11458
Comments
I see in #11226 that async transformations are only supported in ESM mode. So is there any way to use an async transformer without relying on users of the transformer to run jest in ESM mode? My use case is that I am using mdx, which is async by default. So it's not really possible to write this transformer synchronously 🤔 |
I am still having no luck, even when trying to emulate the setup in your tests following this file.
I then run it with I also played around with different ways of running Jest as per the ECMAScript Modules docs like (node:30693) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL ./test.js
● Test suite failed to run
Jest: synchronous transformer jest-transformer-mdx/mdx-transformer.cjs must export a "process" function. I am really trying to copy what is in your tests, am I missing something? Or is this a bug in jest? Also I understand if this goes out of scope of this issue :) |
|
Do you mean to stub module.exports = {
process() {
return ""
},
async processAsync(src, filepath, config) {
// omitted
},
} Which sadly doesn't work. It's using the return value from |
Not sure if .cjs is the issue, what if you use .js for your transformer? |
As for your following error, I assume it's because by default jest loads most files as CJS, you can use You shouldn't need to define |
I did come across import path from "path"
import matter from "gray-matter"
import stringifyObject from "stringify-object"
import mdx from "@mdx-js/mdx"
import babelJest from "babel-jest"
async function processAsync(src, filepath, config) {
// omitted
}
export default { processAsync } However that still gave me FAIL ./test.mdx-options.js
● Test suite failed to run
Must use import to load ES Module: jest-transformer-mdx/test.md
1 | import React from "react"
> 2 | import Component, { frontMatter } from "./test.md"
| ^ I think I am getting very stuck, I have tried:
Even though I know these combinations don't work, I just wanted to explore to see if I got any different errors. On paper, it should work with only exporting processAsync, in |
The transformer can be either ESM or CJS, You get |
What do you mean with "since you use require to load it"? Do you mean inside my test file? As in my test I import the file with So I tried taking this step by step, and wrote the transformer with ESM. I could only get it running without getting No problem though, now the transformer is written with ESM, with the file extension mjs. However now I still get the error from my original issue. If I use ESM with and run jest with With CJS, it runs fine but I also hit the same error from my original issue, |
@bitttttten You might want to try adding |
I ran into this when trying to port a cascading transform from Jest 26 to Jest 27 because the "it will be easy, I just need to change |
But this is just the module resolution, not the execution of the function. If this is true, then no one using a CJS library would be able to use an async function. Which I don't think is true. |
@Jessidhia We discussed some sort of async "setup" function, but ended up with "ESM is enough" (#11081 (comment)). Not sure if that would help in your case... Supporting some way of composing multiple transforms would be pretty nice. Could you open up a new issue with that use case? @sebastianrothe I don't really follow what you're saying. Jest implementing JIT transforms, so |
@SimenB I was wondering, if an exclusive ( |
That's not possible unfortunately as CJS cannot be asynchronous |
But then this transformer https://github.com/facebook/jest/blob/master/e2e/transform/async-transformer/my-transform.cjs gets transpiled to ESM? Ah, the test itself is ESM https://github.com/facebook/jest/blob/main/e2e/transform/async-transformer/__tests__/test.js |
I have been waiting months to see whether this issue would be addressed. When I update to Babel/Jest 27 all of my almost 300 test suites fail with: Jest: a transform must export a at ScriptTransformer._getTransformer (node_modules/jest-runner/node_modules/@jest/transform/build/ScriptTransformer.js:368:15) https://github.com/CourtHive/tods-competition-factory |
I'll close this as the OP answered themselves in the first comment.
No, when a user calls I'll add that you can use @CourtHive feel free to open up a new issue with minimal reproduction steps. |
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. |
To Reproduce
When running on CI I get this error:
You can see the CI result here, and you can view the transformer here.
Expected behavior
It matches what happens when I run the tests locally:
Link to repl or repo (highly encouraged)
All the files are in the public repo: https://github.com/bitttttten/jest-transformer-mdx
envinfo
CI
Local machine
The text was updated successfully, but these errors were encountered: