esbuild-kit/cjs-loader

feature request: export an unregister method for returning to Node's require methods

dylang opened this issue · 3 comments

In my Jest config I have import '@esbuild-kit/cjs-loader'; so that the config can load node modules that use ESM.

However, because we don't have a way to unregister the loader, it continues to be used through all of the tests, slowing down Jest and double-compiling those that we want transformed.

Ideally, it would be something like:

import { unregisterLoader } from '@esbuild-kit/cjs-loader';
import { } from 'esm module 1';
import { } from 'esm module 2';

unregisterLoader();

// rest of Jest config.

Why would it be double compiled? And what's the slowdown you're experiencing?

Why would it be double compiled?

We have a jest transform transforming the code.

So esbuild-kit is transforming code when it is requireed, AND jest is transforming the code through it's module loader.

And what's the slowdown you're experiencing?

It's possible that it added ~10 minutes to a project with 17,897 tests that was taking 35 minutes before adding import '@esbuild-kit/cjs-loader', but I could be wrong, our CI system sometimes has bad noisy neighbor issues that slow down our tests.

Hi @privatenumber -

I decided that our goals aren't the same and it would be best to build our own ESM loader using babel-core so you don't need to make changes you don't want and we're not blocked by bugs introduced by nuances in ESBuild.

I truly appreciate your hard work on this project. You helped us finally be able to use third-party ESM modules. I hope we can use your work again in the future.