`jest.mock` of ESM should fail, and it's correct
This is not an issue, because the input was already wrong.
If you really want to workaround this, see https://github.com/swc-project/swc/discussions/5151#discussioncomment-3149154 Note that this is not an official one, and it will break frequently.
jest not working with ESM is not an issue of swc. See https://github.com/facebook/jest/issues/9430
common js vs ESM behavior
Technically this can be workarounded by SWC by compiling in a wrong way.
But ESM is an established standard, and swc follows the specification. If you use ESM as input, swc will compile the code to behave in a way defined by the specification.
You may claim the official typescript compiler does not follow specification if module type is common js, but it's a bug of tsc. If you want behavior of common js, you can write a common js module instead.
Discussions
- https://github.com/swc-project/swc/discussions/5151
Issues
- https://github.com/swc-project/swc/issues/3843
- https://github.com/swc-project/swc/issues/4455
- https://github.com/swc-project/swc/issues/5059
- https://github.com/swc-project/swc/issues/5204
For the opinions / suggestions, please use general discussions https://github.com/swc-project/swc/discussions/5151.
For the workaround, please refer https://github.com/swc-project/swc/discussions/5151#discussioncomment-3149154= .
This issue itself is an announcement, will be locked to avoid diverging comments between existing discussions.
Closing in favor of https://github.com/swc-project/swc/issues/7435