Fix esm compatibility with jest
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:
- Create
package.jsonfile
{
"scripts": {
"test": "jest"
},
"devDependencies": {
"babel-loader": "9.1.3",
"jest": "29.6.2"
}
}
- Create
babel.test.jsfile
test('should import babel-loader correctly', () => {
expect(require('babel-loader')).toBeInstanceOf(Function);
});
- 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
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Thanks! Does this actually fix compatibility? You can now require it, but can you use it in jest?
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.