In my Next.js 12 App with the Rust Compiler, I am utilizing Jest and WebWorkers. In one of my files, I am using import.meta.url.
to create the worker.
The issue arises when Jest throws an error, stating that import.meta.url
cannot be used outside of an ES Module due to transforming TypeScript code to CommonJs format. I came across a solution involving a Babel plugin that can transform these specific files containing import.meta.url
. More details can be found here: https://github.com/facebook/jest/issues/12183#issuecomment-1004320665
However, I am hesitant to use Babel as my Jest configuration is based on Next's setup with the Rust compiler. It is unclear whether I can incorporate this babel plugin into my current configuration.
I am aware that another approach could be configuring Jest to use ESModules instead. However, I am reluctant to go down this path as it is still experimental and has caused some unexpected errors in my project.
Therefore, my question is: Is there a way (or perhaps a SWC plugin) to achieve this transformation using SWC?