{"record":{"id":"84ed62ae9bffab11","repo":"jestjs/jest","slug":"babel-jest-babel-ignores-chalk-bold-slash-path","errorCode":null,"errorMessage":"babel-jest: Babel ignores ${chalk.bold(slash(path.relative(cwd, filename)))} - make sure to include the file in Jest's ${chalk.bold('transformIgnorePatterns')} as well.","messagePattern":"babel-jest: Babel ignores (.+?) - make sure to include the file in Jest's (.+?) as well\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/babel-jest/src/index.ts","lineNumber":43,"sourceCode":"  loadPartialConfigAsync,\n  loadPartialConfigSync,\n} from './babel';\n\nexport interface TransformerConfig extends BabelTransformOptions {\n  excludeJestPreset?: boolean;\n}\n\nconst THIS_FILE = fs.readFileSync(__filename);\nconst jestPresetPath = require.resolve('babel-preset-jest');\nconst babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');\n\nfunction assertLoadedBabelConfig(\n  babelConfig: Readonly<PartialConfig> | null,\n  cwd: string,\n  filename: string,\n): asserts babelConfig {\n  if (!babelConfig) {\n    throw new Error(\n      `babel-jest: Babel ignores ${chalk.bold(\n        slash(path.relative(cwd, filename)),\n      )} - make sure to include the file in Jest's ${chalk.bold(\n        'transformIgnorePatterns',\n      )} as well.`,\n    );\n  }\n}\n\nfunction addIstanbulInstrumentation(\n  filename: string,\n  babelOptions: BabelTransformOptions,\n  transformOptions: JestTransformOptions,\n): BabelTransformOptions {\n  if (transformOptions.instrument) {\n    const copiedBabelOptions: BabelTransformOptions = {\n      ...babelOptions,\n      auxiliaryCommentBefore: ' istanbul ignore next ',","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/babel-jest/src/index.ts#L25-L61","documentation":"babel-jest throws this when Babel's loadPartialConfig (sync or async) returns null for a file Jest asked it to transform, meaning Babel itself decided to ignore that file. This happens when the file falls outside Babel's config scope (rootMode/babelrcRoots) or matches Babel's own ignore/exclude rules, so there is no config to transform with. The message points at Jest's transformIgnorePatterns because the usual intent is either to let Jest skip transforming that file or to widen Babel's config to cover it.","triggerScenarios":"Jest's transform pipeline routes a source file to babel-jest (the file matched the `transform` regex and was not in `transformIgnorePatterns`), but `loadPartialConfigSync`/`loadPartialConfigAsync` from @babel/core returns null. Common when importing compiled ESM/CJS from node_modules that Jest is forced to transform, or when a file sits in a workspace whose babel.config.js does not apply (different `rootDir`, missing `babelrcRoots`).","commonSituations":"Monorepo workspaces where the root babel.config.js does not reach sibling packages; upgrading to Babel 7 with config files that use `rootMode: 'upward'` but jest config does not set it; importing third-party ESM packages published as `.mjs`/ESM that Jest must transform; a `.babelrc.json` with an `ignore` pattern that excludes the test file itself.","solutions":["If the file should NOT be transformed by babel-jest, add its path to Jest's `transformIgnorePatterns` so Jest never sends it to babel-jest.","If the file SHOULD be transformed, ensure a Babel config applies to it: add/extend a `babel.config.js` at the project root or set `babelrcRoots` / `rootMode: 'upward'` in your babel-jest transformer options so the config reaches the file's directory.","For monorepos, set Jest's `rootDir`/`roots` and Babel's `root`/`rootMode` consistently so the file resolves under the same Babel root.","If using a custom transformer via `createTransformer`, pass `rootMode: 'upward'` in the babel-jest options (e.g. `transform: { '^.+\\\\.jsx?$': ['babel-jest', { rootMode: 'upward' }] }`)."],"exampleFix":"// before (jest.config.js)\nmodule.exports = { transform: { '^.+\\\\.jsx?$': 'babel-jest' } };\n// file in packages/foo ignored by root babel config -> error\n\n// after (option A: let babel reach it)\nmodule.exports = {\n  transform: {\n    '^.+\\\\.jsx?$': ['babel-jest', { rootMode: 'upward' }],\n  },\n};\n\n// after (option B: stop transforming the ignored path)\nmodule.exports = {\n  transformIgnorePatterns: ['/node_modules/(?!(some-pkg)/)', 'packages/foo/ignored-dir'],\n};","handlingStrategy":"validation","validationCode":"// Before relying on babel-jest to transform a file, confirm Babel will not ignore it.\nimport {loadPartialConfigSync} from '@babel/core';\n\nfunction babelWillTransform(filename, babelOptions) {\n  const cfg = loadPartialConfigSync({filename, ...babelOptions});\n  return cfg != null; // if false, expect the 'Babel ignores' error from babel-jest\n}\n\n// In jest.config, decide based on this:\nconst transform = babelWillTransform('src/odd.js', opts)\n  ? {'^.+\\\\.jsx?$': 'babel-jest'}\n  : {'^.+\\\\.jsx?$': ['babel-jest', {rootMode: 'upward'}]};","typeGuard":"// Narrow a jest transform config so ignored paths are excluded up front.\nfunction buildTransform(babelRoot, ignoredPaths) {\n  return {\n    '^.+\\\\.jsx?$': ['babel-jest', {root: babelRoot, rootMode: babelRoot ? 'root' : 'upward'}],\n    transformIgnorePatterns: ['/node_modules/', ...ignoredPaths],\n  };\n}","tryCatchPattern":"try {\n  // run a single throwaway transform to surface config issues early\n  require('babel-jest').createTransformer({rootMode: 'upward'}).process(source, filename, opts);\n} catch (e) {\n  if (/Babel ignores/.test(e.message)) {\n    // adjust transformIgnorePatterns or babel rootMode, then retry\n  } else throw e;\n}","preventionTips":["Keep Jest's `rootDir`/`roots` and Babel's `root`/`rootMode` aligned in monorepos.","Set `rootMode: 'upward'` in babel-jest options when configs live above the package.","Use `transformIgnorePatterns` deliberately for node_modules that must (or must not) be transformed.","Add a smoke test that transforms one file per workspace to catch config-scope regressions in CI."],"tags":["babel","jest-transform","configuration","monorepo"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}