Skip to content

Commit b64f9b7

Browse files
Fix jest imports of temporal-polyfill
1 parent 27eb2f9 commit b64f9b7

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

app/web/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const customJestConfig: Config = {
3030
// @TODO(NA) ^^ Fixed in react-query v4, but we are still on v3. Remove this when we upgrade.
3131
moduleDirectories: ["node_modules", "<rootDir>"],
3232
reporters: ["default", "jest-junit"],
33+
resolver: "<rootDir>/jest.resolver.js",
3334
setupFilesAfterEnv: ["./test/setupTests.ts"],
3435
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.next/"],
3536
testEnvironment: "jsdom",
@@ -38,7 +39,6 @@ const customJestConfig: Config = {
3839
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
3940
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
4041
},
41-
transformIgnorePatterns: ["/node_modules/"],
4242
resetMocks: true,
4343
};
4444

app/web/jest.resolver.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// temporal-polyfill and temporal-utils only publish an "import" export condition, which
2+
// Jest's default CJS module resolution doesn't request, so plain `require()` resolution
3+
// fails with "Cannot find module". Request the "import" condition just for these packages
4+
// instead of globally (globally breaks other node_modules that pick their unbuilt ESM entry
5+
// over a CJS one, e.g. dedent).
6+
const ESM_ONLY_PACKAGES = ["temporal-polyfill", "temporal-utils"];
7+
8+
module.exports = (path, options) => {
9+
const isEsmOnly = ESM_ONLY_PACKAGES.some(
10+
(name) => path === name || path.startsWith(`${name}/`),
11+
);
12+
if (isEsmOnly) {
13+
return options.defaultResolver(path, {
14+
...options,
15+
conditions: [...(options.conditions ?? []), "import"],
16+
});
17+
}
18+
return options.defaultResolver(path, options);
19+
};

app/web/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const nextConfig = {
2323
},
2424
i18n,
2525
productionBrowserSourceMaps: true,
26+
// ESM-only packages with no CommonJS entry point - Next.js (and next/jest) need to
27+
// transpile these themselves rather than treating them as pre-built node_modules.
28+
transpilePackages: ["temporal-polyfill", "temporal-utils"],
2629
webpack: (config, { isServer }) => {
2730
if (isServer) {
2831
generateBlogIndex();

0 commit comments

Comments
 (0)