You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Jest fails with universal-cookie error when frontend-base is in packages #287
FAIL src/Main.test.tsx
● Test suite failed to run
TypeError: _universalCookie.default is not a constructor
8 | import { publish } from '../subscriptions';
9 |
> 10 | const cookies = new Cookies();
| ^
Reason (thanks Claude!):
createConfig('test') sets rootDir: process.cwd() and leaves roots at its default ([rootDir]), so jest-haste-map crawls your whole app directory — including packages/frontend-base/. (It skips node_modules, so when frontend-base comes from npm as usual, its __mocks__ folders are invisible). Now that it's a real workspace directory, two of them get registered:
packages/frontend-base/shell/__mocks__/universal-cookie.js
(the dist/ copies are excluded by modulePathIgnorePatterns, which is why it's exactly two.)
For a node module, a registered manual mock is applied automatically — no jest.mock() call needed. So every one of your test suites silently gets frontend-base's mock of universal-cookie, and that mock is:
module.exports = () => mockCookiesImplementation;
An arrow function has no [[Construct]], so runtime/i18n/lib.ts:10's new Cookies() throws _universalCookie.default is not a constructor.
A solution is to add roots: ['<rootDir>/src'], to jest.config.js, or to fix the mock(s) to support new properly like the code they're mocking.
Side node: jest-haste-map is always throwing warnings about duplicate mocks, and I'm unclear why we're using it at all.
Activity
fix: keep frontend-base out of a consuming app's jest crawl
openedx-semantic-release-bot commentedon Aug 29, 2026
🎉 This issue has been resolved in version 2.0.0-alpha.6 🎉
The release is available on:
Your semantic-release bot 📦🚀