{"id":"01c0ce311f419873","repo":"jestjs/jest","slug":"babel-jest-babel-ignores-slash-path-relative-cw","errorCode":null,"errorMessage":"babel-jest: Babel ignores ${slash(path.relative(cwd, filename))} - make sure to include the file in Jest's transformIgnorePatterns as well.","messagePattern":"babel-jest: Babel ignores (.+?) - make sure to include the file in Jest's transformIgnorePatterns 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/f49721c78e195558b40913977c9230f5b7f559d8/packages/babel-jest/src/index.ts#L25-L61","documentation":"babel-jest delegates transformation to Babel by calling loadPartialConfigSync/Async; when Babel's config resolution returns null it means Babel itself has decided to ignore that file (no applicable babel.config.js/babelrc, or an `ignore`/`only` rule excluded it). Because babel-jest cannot produce transformed output without a Babel config, assertLoadedBabelConfig throws to tell you the file Jest asked it to transform is invisible to Babel. The message points at transformIgnorePatterns because the usual resolution is to make Jest stop asking babel-jest to transform that file.","triggerScenarios":"Jest's transform mapping routes a file to babel-jest (e.g. the default .js/.jsx transform, or a custom transform entry), and Babel's loadPartialConfigSync returns null for that filename. Common concrete triggers: a file outside the Babel rootMode/upward search range, a babel.config.js with an `ignore` glob that catches the file, a monorepo package lacking a babelrc while rootMode:'upward' cannot find the root config, or a node_modules source file that Jest is transforming because transformIgnorePatterns was widened.","commonSituations":"Monorepos where one package has a .babelrc and another doesn't; upgrading Babel 6->7 and forgetting babel.config.js; setting `transform` to babel-jest for .ts/.tsx without @babel/preset-typescript installed; ESM projects where `type:module` plus a misconfigured babel config makes Babel skip files; CI builds that differ from local because a babel plugin is in devDependencies and was hoisted differently.","solutions":["Add the file path/pattern to Jest's transformIgnorePatterns so Jest stops trying to transform it (default already ignores node_modules; narrow or widen as needed).","Ensure a Babel config (babel.config.js or .babelrc) actually applies to the file: check `rootMode`, `babelrcRoots`, and that the file is under a covered directory.","If you do want the file transformed, pass explicit babelOptions via the transformer config in jest.config.js so Babel does not return null.","Verify with `npx babel <file>` (or `babel --show-config <file>`) that Babel sees a config for that path; if it prints an empty config, that confirms the ignore."],"exampleFix":"// before (jest.config.js) — file under packages/foo is ignored by Babel\nexport default { transform: { '^.+\\\\.jsx?$': 'babel-jest' } };\n\n// after — tell Jest not to transform the problematic path, OR cover it with Babel\nexport default {\n  transform: { '^.+\\\\.jsx?$': 'babel-jest' },\n  transformIgnorePatterns: ['/node_modules/', 'packages/legacy/'],\n}\n// and in babel.config.js make sure the root covers all packages:\n// module.exports = { rootMode: 'upward-optional' };","handlingStrategy":"validation","validationCode":"const rel = path.relative(jestConfig.rootDir, filename);\nconst isIgnoredByJest = (jestConfig.transformIgnorePatterns ?? []).some(p =>\n  new RegExp(p).test(rel),\n);\n// Before relying on babel-jest, ensure Babel actually sees the file:\nconst {loadPartialConfigSync} = require('@babel/core');\nconst cfg = loadPartialConfigSync({ filename, cwd: jestConfig.rootDir, rootMode: 'upward' });\nif (cfg === null && !isIgnoredByJest) {\n  throw new Error(`babel-jest would throw on ${filename}; add it to transformIgnorePatterns or extend Babel config.`);\n}","typeGuard":"// n/a — configuration-level error, not a value-shape problem","tryCatchPattern":"try {\n  transformer.process(sourceText, sourcePath, opts);\n} catch (e) {\n  if (/babel-jest: Babel ignores/.test(String(e?.message))) {\n    // Add sourcePath to transformIgnorePatterns or extend Babel config, then retry.\n  }\n  throw e;\n}","preventionTips":["Keep transformIgnorePatterns and Babel's config coverage in sync: every path Jest routes to babel-jest must be visible to Babel.","In monorepos set rootMode:'upward' (or babelrcRoots) so all packages resolve the root babel.config.js.","Run `npx babel --show-config <file>` as a CI check to confirm Babel sees each transformed path."],"tags":["babel","jest","transform","configuration","monorepo"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}