{"id":"d43186dfd73421aa","repo":"jestjs/jest","slug":"no-exports-found-in-package-pkg-name","errorCode":null,"errorMessage":"No exports found in package ${pkg.name}","messagePattern":"No exports found in package (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/build.mjs","lineNumber":79,"sourceCode":"      `Main file \"${pkg.main}\" in \"${pkg.name}\" should exist`,\n    );\n\n    if (typeOnlyPackages.has(pkg.name)) {\n      continue;\n    }\n\n    // TODO: can we get exports from a file from webpack's `stats`?\n    const cjsModule = require(entryPointFile);\n    const exportStatements = Object.keys(cjsModule)\n      .filter(name => name !== '__esModule' && name !== 'default')\n      .map(name => `export const ${name} = cjsModule.${name};`);\n\n    if (cjsModule.default) {\n      exportStatements.push('export default cjsModule.default;');\n    }\n\n    if (exportStatements.length === 0) {\n      throw new Error(`No exports found in package ${pkg.name}`);\n    }\n\n    const mjsEntryFile = entryPointFile.replace(/\\.js$/, '.mjs');\n\n    const esSource = dedent`\n      import cjsModule from './index.js';\n\n      ${exportStatements.join('\\n')}\n    `;\n\n    await fs.promises.writeFile(mjsEntryFile, `${esSource}\\n`);\n  }\n\n  process.stdout.write(`${OK}\\n`);\n}\n\ntry {\n  await buildNodePackages();","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/scripts/build.mjs#L61-L97","documentation":"scripts/build.mjs generates an ESM (.mjs) re-export wrapper by requiring the package's CJS entry point (pkg.main) and enumerating its named/default exports. At build.mjs:78-79, if Object.keys(cjsModule) contains nothing other than __esModule/default, the package is considered to export nothing and the build aborts. This catches packages whose entry file has no real public surface before shipping a broken .mjs.","triggerScenarios":"Running the monorepo build (`node scripts/build.mjs` / the build script) for a package whose index.js has no exports — e.g. a barrel file that forgot to re-export, a file with only internal helper declarations, or one where exports are guarded behind a condition that evaluates false at require time.","commonSituations":"Adding a new package but not yet exporting anything from its entry point; refactoring that moves exports into a sub-module without re-exporting from index.js; side-effectful entry files that assign to a conditional that is falsy during build.","solutions":["Add at least one named or default export to the package's main entry file (the file referenced by pkg.main).","Confirm pkg.main points at the intended entry file and that file was built (the script first asserts fs.existsSync(entryPointFile)).","Re-run the build after fixing exports; the require() at build.mjs:69 must observe real keys."],"exampleFix":"// before (packages/foo/build/index.js)\nfunction internal() {}\nmodule.exports = {};\n// after\nfunction foo() { return 'foo'; }\nmodule.exports = { foo };","handlingStrategy":"validation","validationCode":"function assertPackageHasExports(entryFile, pkgName) {\n  const mod = require(entryFile);\n  const names = Object.keys(mod).filter(k => k !== '__esModule' && k !== 'default');\n  if (names.length === 0 && !mod.default) {\n    throw new Error(`No exports found in package ${pkgName}`);\n  }\n}","typeGuard":"function packageHasExports(entryFile) {\n  const mod = require(entryFile);\n  const named = Object.keys(mod).filter(k => k !== '__esModule' && k !== 'default');\n  return named.length > 0 || !!mod.default;\n}","tryCatchPattern":null,"preventionTips":["Ensure every package's main entry file exports at least one named or default binding.","Verify pkg.main points at the correct built file before running the monorepo build.","Add a smoke test that requires each package entry and asserts it has a non-empty export surface."],"tags":["build","monorepo","esm","cjs","exports"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}