From b29a5c53edb59d79aa28e09492b89bf3584e1614 Mon Sep 17 00:00:00 2001 From: Mitchell Hamilton Date: Fri, 30 Oct 2020 14:06:15 +1000 Subject: [PATCH 1/2] Get around a rollup bug in the new interfaces (#4084) --- packages-next/admin-ui/src/apollo.tsx | 19 ++++++++++++++++++- packages-next/admin-ui/src/router.tsx | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages-next/admin-ui/src/apollo.tsx b/packages-next/admin-ui/src/apollo.tsx index 2c9e74bed5d..436d6079ea6 100644 --- a/packages-next/admin-ui/src/apollo.tsx +++ b/packages-next/admin-ui/src/apollo.tsx @@ -3,4 +3,21 @@ * packages import the same instance of apollo. */ -export * from '@apollo/client'; +// not using export * because Rollup emits CJS code that redefines __esModule which causes problems because __esModule generally isn't a configurable property +export { + useQuery, + useMutation, + useLazyQuery, + gql, + ApolloError, + InMemoryCache, + ApolloClient, + ApolloProvider, +} from '@apollo/client'; +export type { + ServerError, + ServerParseError, + QueryResult, + DocumentNode, + TypedDocumentNode, +} from '@apollo/client'; diff --git a/packages-next/admin-ui/src/router.tsx b/packages-next/admin-ui/src/router.tsx index d7ca0d734da..938563ccb5d 100644 --- a/packages-next/admin-ui/src/router.tsx +++ b/packages-next/admin-ui/src/router.tsx @@ -3,7 +3,10 @@ * packages import the same instance of next's router. */ -export * from 'next/router'; +// not using export * because Rollup emits CJS code that redefines __esModule which causes problems because __esModule generally isn't a configurable property +export { createRouter, makePublicRouterInstance, Router, useRouter, withRouter } from 'next/router'; +export type { NextRouter } from 'next/router'; + import NextLink, { LinkProps as NextLinkProps } from 'next/link'; import React, { AnchorHTMLAttributes } from 'react'; From d91a638352f637e95fe6ffed9268e2ed9950e2c5 Mon Sep 17 00:00:00 2001 From: Mitchell Hamilton Date: Fri, 30 Oct 2020 14:39:15 +1000 Subject: [PATCH 2/2] Only work around Rollup bug for router entrypoint in new interfaces (#4085) --- packages-next/admin-ui/src/apollo.tsx | 19 +------------------ packages-next/admin-ui/src/router.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/packages-next/admin-ui/src/apollo.tsx b/packages-next/admin-ui/src/apollo.tsx index 436d6079ea6..2c9e74bed5d 100644 --- a/packages-next/admin-ui/src/apollo.tsx +++ b/packages-next/admin-ui/src/apollo.tsx @@ -3,21 +3,4 @@ * packages import the same instance of apollo. */ -// not using export * because Rollup emits CJS code that redefines __esModule which causes problems because __esModule generally isn't a configurable property -export { - useQuery, - useMutation, - useLazyQuery, - gql, - ApolloError, - InMemoryCache, - ApolloClient, - ApolloProvider, -} from '@apollo/client'; -export type { - ServerError, - ServerParseError, - QueryResult, - DocumentNode, - TypedDocumentNode, -} from '@apollo/client'; +export * from '@apollo/client'; diff --git a/packages-next/admin-ui/src/router.tsx b/packages-next/admin-ui/src/router.tsx index 938563ccb5d..feb69e8656e 100644 --- a/packages-next/admin-ui/src/router.tsx +++ b/packages-next/admin-ui/src/router.tsx @@ -3,7 +3,12 @@ * packages import the same instance of next's router. */ -// not using export * because Rollup emits CJS code that redefines __esModule which causes problems because __esModule generally isn't a configurable property +// not using export * because Rollup's CJS re-export code doesn't ignore __esModule on the exports object so it will re-define it if it exists +// and since __esModule isn't configurable(at least with the code that's _generally_ emitted by Rollup, Babel, tsc and etc.) +// an error will be thrown +// that's normally not a problem because modules generally use Object.defineProperty(exports, '__esModule', { value: true }) +// which means that the property isn't enumerable but Next uses Babel's loose mode and Babel's loose mode for the CJS transform +// uses exports.__esModule = true instead of defineProperty so the property is enumerable export { createRouter, makePublicRouterInstance, Router, useRouter, withRouter } from 'next/router'; export type { NextRouter } from 'next/router';