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

Fix esm compatibility with jest #1005

Closed
wants to merge 1 commit into from
Closed

Fix esm compatibility with jest #1005

wants to merge 1 commit into from

Conversation

ahce
Copy link

@ahce ahce commented Aug 12, 2023

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Steps to reproduce:

  1. Create package.json file
{
  "scripts": {
    "test": "jest"
  },
  "devDependencies": {
    "babel-loader": "9.1.3",
    "jest": "29.6.2"
  }
}
  1. Create babel.test.js file
test('should import babel-loader correctly', () => {
  expect(require('babel-loader')).toBeInstanceOf(Function);
});
  1. Run test
    Test fail: Error: You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/ecmascript-modules

What is the new behavior?

The test pass successfully
image

Does this PR introduce a breaking change?

  • Yes
  • No

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Aug 13, 2023

Thanks! Does this actually fix compatibility? You can now require it, but can you use it in jest?

@ahce
Copy link
Author

ahce commented Aug 15, 2023

Thanks! Does this actually fix compatibility? You can now require it, but can you use it in jest?

Thanks for your reply!
I have a custom webpack plugin integrated with babel-loader, and from version 9.1.3 my tests fail.
I detected that in v9.1.3 this change was introduced in #995.
I applied this fix directly in node_modules and my tests work correctly.

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.

2 participants