Unverified Commit 96cc789f authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

transpilePackages should override default settings for external packages (#59385)

See related https://github.com/vercel/next.js/issues/51969. It should no
longer apply.
parent c964e9a4
......@@ -116,6 +116,9 @@ pub async fn get_server_resolve_options_context(
)
.await?;
let transpile_packages = next_config.transpile_packages().await?;
external_packages.retain(|item| !transpile_packages.contains(item));
// Add the config's own list of external packages.
external_packages.extend(
(*next_config.server_component_externals().await?)
......
......@@ -732,10 +732,28 @@ export default async function getBaseWebpackConfig(
const crossOrigin = config.crossOrigin
// The `serverComponentsExternalPackages` should not conflict with
// the `transpilePackages`.
if (
config.experimental.serverComponentsExternalPackages &&
config.transpilePackages
) {
const externalPackageConflicts = config.transpilePackages.filter((pkg) =>
config.experimental.serverComponentsExternalPackages?.includes(pkg)
)
if (externalPackageConflicts.length > 0) {
throw new Error(
`The packages specified in the 'transpilePackages' conflict with the 'serverComponentsExternalPackages': ${externalPackageConflicts.join(
', '
)}`
)
}
}
// For original request, such as `package name`
const optOutBundlingPackages = EXTERNAL_PACKAGES.concat(
...(config.experimental.serverComponentsExternalPackages || [])
)
).filter((pkg) => !config.transpilePackages?.includes(pkg))
// For resolved request, such as `absolute path/package name/foo/bar.js`
const optOutBundlingPackageRegex = new RegExp(
`[/\\\\]node_modules[/\\\\](${optOutBundlingPackages
......
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { GetObjectCommand } from '@aws-sdk/client-s3'
import { isObject } from 'lodash'
export default function Page() {
const command = new GetObjectCommand({
Bucket: 'bucket',
Key: 'key1',
})
return (
<div>
<div id="key">Key: {command.input.Key}</div>
<div id="isObject">isObject: {String(isObject(command))}</div>
</div>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
transpilePackages: ['@aws-sdk/client-s3'],
}
module.exports = nextConfig
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")')
})
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment