diff --git a/test/production/transpile-packages/app/layout.tsx b/test/production/transpile-packages/app/layout.tsx new file mode 100644 index 0000000000000..e7077399c03ce --- /dev/null +++ b/test/production/transpile-packages/app/layout.tsx @@ -0,0 +1,7 @@ +export default function Root({ children }: { children: React.ReactNode }) { + return ( + + {children} + + ) +} diff --git a/test/production/transpile-packages/app/page.tsx b/test/production/transpile-packages/app/page.tsx new file mode 100644 index 0000000000000..ff566a26af6cb --- /dev/null +++ b/test/production/transpile-packages/app/page.tsx @@ -0,0 +1,15 @@ +import { GetObjectCommand } from '@aws-sdk/client-s3' +import { isObject } from 'lodash' + +export default function Page() { + const command = new GetObjectCommand({ + Bucket: 'bucket', + Key: 'key1', + }) + return ( +
+
Key: {command.input.Key}
+
isObject: {String(isObject(command))}
+
+ ) +} diff --git a/test/production/transpile-packages/next.config.js b/test/production/transpile-packages/next.config.js new file mode 100644 index 0000000000000..78ffb37e3fc8d --- /dev/null +++ b/test/production/transpile-packages/next.config.js @@ -0,0 +1,8 @@ +/** + * @type {import('next').NextConfig} + */ +const nextConfig = { + transpilePackages: ['@aws-sdk/client-s3'], +} + +module.exports = nextConfig diff --git a/test/production/transpile-packages/transpile-packages.test.ts b/test/production/transpile-packages/transpile-packages.test.ts new file mode 100644 index 0000000000000..acfc3f1bd56bb --- /dev/null +++ b/test/production/transpile-packages/transpile-packages.test.ts @@ -0,0 +1,29 @@ +import { createNextDescribe } from 'e2e-utils' + +createNextDescribe( + 'app fetch build cache', + { + files: __dirname, + dependencies: { + '@aws-sdk/client-s3': 'latest', + lodash: 'latest', + }, + }, + ({ next }) => { + it('should render page with dependencies', async () => { + const $ = await next.render$('/') + expect($('#key').text()).toBe('Key: key1') + expect($('#isObject').text()).toBe('isObject: true') + }) + + it('should treat lodash as an external package', async () => { + const output = await next.readFile('.next/server/app/page.js') + expect(output).toContain('require("lodash') + }) + + it('should bundle @aws-sdk/client-s3 as a transpiled package', async () => { + const output = await next.readFile('.next/server/app/page.js') + expect(output).not.toContain('require("@aws-sdk/client-s3")') + }) + } +)