diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index 84c1f60be6bc5..4505fefc7b33f 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -218,7 +218,7 @@ export const defaultConfig: NextConfig = { disableOptimizedLoading: false, gzipSize: true, craCompat: false, - esmExternals: false, + esmExternals: true, staticPageGenerationTimeout: 60, // default to 50MB limit isrMemoryCacheSize: 50 * 1024 * 1024, diff --git a/test/integration/externals/next.config.js b/test/integration/externals/next.config.js deleted file mode 100644 index 826c3454030d2..0000000000000 --- a/test/integration/externals/next.config.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - webpack(config) { - config.resolve.alias = { - ...config.resolve.alias, - 'preact/compat': 'react', - } - - return config - }, -} diff --git a/test/integration/externals/node_modules/esm-package/correct.js b/test/integration/externals/node_modules/esm-package/correct.js deleted file mode 100644 index cea6b73e3b7b1..0000000000000 --- a/test/integration/externals/node_modules/esm-package/correct.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'World' diff --git a/test/integration/externals/node_modules/esm-package/package.json b/test/integration/externals/node_modules/esm-package/package.json deleted file mode 100644 index 307908751781d..0000000000000 --- a/test/integration/externals/node_modules/esm-package/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "esm-package", - "exports": { - "./entry": { - "import": "./wrong.mjs", - "require": "./correct.js" - } - } -} diff --git a/test/integration/externals/node_modules/esm-package/wrong.mjs b/test/integration/externals/node_modules/esm-package/wrong.mjs deleted file mode 100644 index 61f4f6857e2f1..0000000000000 --- a/test/integration/externals/node_modules/esm-package/wrong.mjs +++ /dev/null @@ -1,3 +0,0 @@ -if(typeof window === "undefined") - throw new Error("This shouldn't be used on server-side") -export default "World"; diff --git a/test/integration/externals/node_modules/module-package/correct.js b/test/integration/externals/node_modules/module-package/correct.js deleted file mode 100644 index cea6b73e3b7b1..0000000000000 --- a/test/integration/externals/node_modules/module-package/correct.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'World' diff --git a/test/integration/externals/node_modules/module-package/package.json b/test/integration/externals/node_modules/module-package/package.json deleted file mode 100644 index 0fb9324a02f50..0000000000000 --- a/test/integration/externals/node_modules/module-package/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "module-package", - "exports": { - ".": { - "module": "./wrong.mjs", - "import": "./wrong.mjs", - "require": "./correct.js" - } - } -} diff --git a/test/integration/externals/node_modules/module-package/wrong.mjs b/test/integration/externals/node_modules/module-package/wrong.mjs deleted file mode 100644 index 61f4f6857e2f1..0000000000000 --- a/test/integration/externals/node_modules/module-package/wrong.mjs +++ /dev/null @@ -1,3 +0,0 @@ -if(typeof window === "undefined") - throw new Error("This shouldn't be used on server-side") -export default "World"; diff --git a/test/integration/externals/node_modules/preact/compat.js b/test/integration/externals/node_modules/preact/compat.js deleted file mode 100644 index 41152fe16598d..0000000000000 --- a/test/integration/externals/node_modules/preact/compat.js +++ /dev/null @@ -1 +0,0 @@ -throw new Error('Should not be executed') diff --git a/test/integration/externals/pages/ssg.js b/test/integration/externals/pages/ssg.js deleted file mode 100644 index 51e9724dd0627..0000000000000 --- a/test/integration/externals/pages/ssg.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'preact/compat' -import World1 from 'esm-package/entry' -import World2 from 'module-package' - -export async function getStaticProps() { - return { - props: {}, - } -} - -export default function Index(props) { - return ( -
- Hello {World1}+{World2} -
- ) -} diff --git a/test/integration/externals/pages/ssr.js b/test/integration/externals/pages/ssr.js deleted file mode 100644 index 99b6437c0035c..0000000000000 --- a/test/integration/externals/pages/ssr.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'preact/compat' -import World1 from 'esm-package/entry' -import World2 from 'module-package' - -export function getServerSideProps() { - return {} -} - -export default function Index(props) { - return ( -
- Hello {World1}+{World2} -
- ) -} diff --git a/test/integration/externals/pages/static.js b/test/integration/externals/pages/static.js deleted file mode 100644 index d4cb310b28931..0000000000000 --- a/test/integration/externals/pages/static.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'preact/compat' -import World1 from 'esm-package/entry' -import World2 from 'module-package' - -export default function Index(props) { - return ( -
- Hello {World1}+{World2} -
- ) -} diff --git a/test/integration/externals/test/index.test.js b/test/integration/externals/test/index.test.js deleted file mode 100644 index cbf3798772d23..0000000000000 --- a/test/integration/externals/test/index.test.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-env jest */ - -import fs from 'fs-extra' -import { join } from 'path' -import { - nextBuild, - findPort, - nextStart, - killApp, - renderViaHTTP, -} from 'next-test-utils' - -const appDir = join(__dirname, '../') -let appPort -let app - -describe('Handle ESM externals', () => { - beforeAll(async () => { - await fs.remove(join(appDir, '.next')) - await nextBuild(appDir) - appPort = await findPort() - app = await nextStart(appDir, appPort) - }) - afterAll(() => killApp(app)) - - const expected = /Hello World\+World/ - - it('should render the static page', async () => { - const html = await renderViaHTTP(appPort, '/static') - expect(html).toMatch(expected) - }) - - it('should render the ssr page', async () => { - const html = await renderViaHTTP(appPort, '/ssr') - expect(html).toMatch(expected) - }) - - it('should render the ssg page', async () => { - const html = await renderViaHTTP(appPort, '/ssg') - expect(html).toMatch(expected) - }) -})