File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments