2

Im trying to resolve the issue I encounter when Im trying to update jest in my package.json

jest 26.6.3 → 27.0.1

Im receiving error

TypeError: require(...).createTransformer is not a function
at Object.<anonymous> (/local/repo/elukchm/monorepo/packages/edf/jestPreprocess.js:34:40)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)

The code mentioned in files:

jestPreprocess.js

const babelOptions = {
...
};

module.exports = require("babel-jest").createTransformer(babelOptions);

Inside "babel-jest"

const createTransformer = userOptions => {
var _inputOptions$plugins, _inputOptions$presets;

const inputOptions =
userOptions !== null && userOptions !== void 0 ? userOptions : {};
const options = {
...
};

Could you please take a look and tell what should I change? Thank you in advance.

0

1 Answer 1

8

babel-jest@27 switched to ESM, so require is now getting the whole exported scope rather than just the default. Super simple to fix:

module.exports = require("babel-jest").createTransformer(babelOptions);
-->
module.exports = require("babel-jest").default.createTransformer(babelOptions);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.