Skip to content
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

Support custom loaders in ESM format #6660

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

eirikur-nc
Copy link

@eirikur-nc eirikur-nc commented Nov 7, 2024

Description

Use a dynamic import when loading custom loaders in order to support loaders in ESM format.
Retain the original implementation, which relies on createRequire, for the synchronous version useCustomLoaderSync

Related #6656

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I could not reproduce the issue using Jest, as it transpiles esm to commonjs.

To keep transpilation to a minimum, I added a test that can be run using the Node.js test runner with type-stripping enabled (requires version 22.6 or later). I also added a convenience script to the root package.json file so that the test can be run using yarn test:node

I realize that having to use two test runners is not ideal. I'm open to suggestions if there's a simpler way to demonstrate the effectiveness of this fix.

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

I fear that Jest may be transpiling the ESM loader.
I'll need to try using another test runner (Vitest or Node)
This one fails like it should for ESM.
Copy link

changeset-bot bot commented Nov 7, 2024

⚠️ No Changeset found

Latest commit: c4a1bf9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@eirikur-nc eirikur-nc changed the title Support esm custom loaders Support custom loaders in ESM format Nov 7, 2024
@eirikur-nc eirikur-nc force-pushed the support-esm-custom-loaders branch from b3e2b48 to 3c30642 Compare November 8, 2024 09:15
@eirikur-nc eirikur-nc marked this pull request as ready for review November 8, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant