babel-loader icon indicating copy to clipboard operation
babel-loader copied to clipboard

Fix esm compatibility with jest

Open ahce opened this issue 1 year ago • 2 comments

What kind of change does this PR introduce?

  • [x] 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
  • [x] No

ahce avatar Aug 12 '23 17:08 ahce

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

nicolo-ribaudo avatar Aug 13 '23 08:08 nicolo-ribaudo

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.

ahce avatar Aug 15 '23 02:08 ahce