{"record":{"id":"5ade6de4c97b7b60","repo":"flarum/framework","slug":"flarum-jest-config-could-not-locate-flarum-core-expected-a","errorCode":null,"errorMessage":"@flarum/jest-config could not locate Flarum core. Expected a Composer-vendored copy at `vendor/flarum/core/js`, or the `@flarum/core` package (inside the monorepo). Run `composer install` so `flarum/core` is present, then try again.","messagePattern":"@flarum/jest-config could not locate Flarum core\\. Expected a Composer-vendored copy at `vendor/flarum/core/js`, or the `@flarum/core` package \\(inside the monorepo\\)\\. Run `composer install` so `flarum/core` is present, then try again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"js-packages/jest-config/index.cjs","lineNumber":60,"sourceCode":"  // test is the authority on where its own core lives, and this is checked\n  // relative to the extension (cwd), not to where this package happens to sit.\n  //\n  // `cwd` is the directory jest runs from — the extension's `js` dir for a\n  // typical layout — so look for the vendor path from there and from its\n  // parent (extensions keep `vendor/` beside `js/`, not inside it).\n  for (const base of [cwd, path.resolve(cwd, '..')]) {\n    const vendored = path.resolve(base, 'vendor/flarum/core/js');\n\n    if (fs.existsSync(vendored)) {\n      return vendored;\n    }\n  }\n\n  try {\n    // Monorepo (or any install where @flarum/core resolves as a package).\n    return path.dirname(require.resolve('@flarum/core/package.json', { paths: [cwd, __dirname] }));\n  } catch (e) {\n    throw new Error(\n      '@flarum/jest-config could not locate Flarum core. Expected a Composer-vendored copy at ' +\n        '`vendor/flarum/core/js`, or the `@flarum/core` package (inside the monorepo). Run ' +\n        '`composer install` so `flarum/core` is present, then try again.'\n    );\n  }\n}\n\nmodule.exports = (options = {}) => {\n  const cwd = process.cwd();\n  const coreDir = resolveCoreDir(cwd);\n\n  return {\n    testEnvironment: 'jsdom',\n    extensionsToTreatAsEsm: ['.ts', '.tsx'],\n    // Everything is transformed by babel-jest, which understands Flarum's\n    // Mithril-flavoured JSX (pragma `m`). We force `@babel/preset-env` to emit\n    // ES modules (`modules: false`) so the output matches\n    // `extensionsToTreatAsEsm` — the shared babel config defaults to `auto`,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/js-packages/jest-config/index.cjs#L42-L78","documentation":"@flarum/jest-config's resolveCoreDir() locates Flarum core JS by trying a Composer-vendored copy at vendor/flarum/core/js and then require.resolve('@flarum/core/package.json'); if both fail it throws this Error. The package needs core's js source to configure the Jest transform/JSM environment. It can only run inside a Flarum install or the monorepo.","triggerScenarios":"Running jest with @flarum/jest-config outside a project where flarum/core is installed: missing `composer install` in a Flarum root, running the package from an isolated npm project, or a repo where @flarum/core isn't linked/vendored.","commonSituations":"Fresh clone of a Flarum extension where composer dependencies were never installed; CI that only ran npm/yarn and skipped Composer; a moved or renamed vendor directory.","solutions":["Run `composer install` in the Flarum root so vendor/flarum/core (including its js directory) exists","In the monorepo, ensure js-packages/@flarum/core is present/resolvable from your working directory","Run your tests from the Flarum project root (cwd) rather than an unrelated directory","If vendoring manually, create vendor/flarum/core/js as a valid copy of core's js folder"],"exampleFix":"// before\n$ npx jest # fails: no vendor/flarum/core\n// after\n$ composer install\n$ npx jest","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nif (!fs.existsSync('vendor/flarum/core/js/package.json')) { throw new Error('Run composer install first'); }","typeGuard":null,"tryCatchPattern":"try { const core = resolveCoreDir(); } catch (e) { console.error('Flarum core missing — run composer install'); process.exit(1); }","preventionTips":["Always run composer install before npm test in Flarum projects","Include composer install in CI before the JS test step","Work from the Flarum root so cwd-based resolution succeeds"],"tags":["javascript","jest","missing-dependency","build-tooling"],"backgroundTag":"missing-dependency","analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}