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
SyntaxError: Unexpected token 'export' when running jest tests #7113
Comments
Thanks, confirmed. I get the same error when running https://github.com/fullcalendar/fullcalendar-examples/tree/main/jest-react |
I am facing the same issue when I moved to |
queued for release 8b0eb87 |
released in v6.0.3 |
@arshaw I'm still experiencing the issue in 6.0.3, please reopen the issue. See repro with 6.0.3 dependencies |
I was using jest 27, which works fine now. I see the problem in jest 28 and above. The problem is happening because jest now looks at the "browser" field in package.json for jsdom. Internally, preact provides a "browser" field, but the file is ESM, which jest does not natively support without a babel transform. I'll look into this more. But a workaround would be ensuring an ESM babel transform is applied to node_modules packages (specifically preact). |
here's a nicer workaround. in your module.exports = {
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: [] // don't load "browser" field
}
}; |
That workaround works, thanks! |
I've updated the repro with the latest version (v6.1.1) and added the above-mentioned fix. It works: https://stackblitz.com/edit/github-sgjd3r-mmezji?file=package.json&view=editor I've mentioned this workaround at the bottom of the fullcalendar-react docs and the example project. |
I had to modify
|
Setting this in your jest config also fixes this issue.
|
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"verbatimModuleSyntax": false
}
}
import type { JestConfigWithTsJest } from 'ts-jest';
import { defaultsESM } from 'ts-jest/presets';
const config: JestConfigWithTsJest = {
...defaultsESM,
moduleNameMapper: {
'^(.+)\\.js$': '$1',
},
preset: 'ts-jest/presets/js-with-ts-esm',
};
export default config; |
Reduced Test Case
https://stackblitz.com/edit/github-sgjd3r?file=src/demo.test.jsx&view=editor
Do you understand that if a reduced test case is not provided, we will intentionally delay triaging of your ticket?
Which connector are you using (React/Angular/etc)?
React
Bug Description
Since upgrading to FullCalendar v6, all my react test in jest are failing with the following error:
SyntaxError: Unexpected token 'export'
Here's the error when I run 'npm run test' in StackBlitz
Edit:
Here's a StackBlitz with v5.11.3 where the test is working. The following release (v6.0.0-beta.2) is not working.
The text was updated successfully, but these errors were encountered: