Skip to content

Commit

Permalink
Use builtin Web Fetch; polyfill not needed in Node.js >= 20
Browse files Browse the repository at this point in the history
Note that we must manually exclude the two polyfill libraries,
unidici and @remix-run/web-fetch, because they are not properly
tree-shaken.
  • Loading branch information
lpsinger committed Dec 16, 2024
1 parent def8c76 commit 5290626
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 18 additions & 1 deletion remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ const esmOnlyModules = [
/^vfile/,
]

// These packages should never be bundled.
const neverBundledModules = [
// Included in AWS Lambda base image
/@?aws-sdk(?:\/|$)/,
// Used to polyfill Web Fetch; not needed for Node.js >= 20
'undici',
'@remix-run/web-fetch',
]

/** @type {import('@remix-run/dev').AppConfig} */
export default {
mdx: {
Expand Down Expand Up @@ -80,7 +89,15 @@ export default {
serverModuleFormat: 'cjs',
serverDependenciesToBundle: [
...esmOnlyModules,
...(isProduction ? [/^(?!@?aws-sdk(\/|$))/] : []),
...(isProduction
? [
new RegExp(
`^(?!${neverBundledModules
.map((item) => (item instanceof RegExp ? item.source : item))
.join('|')})`
),
]
: []),
],
future: { v3_relativeSplatPath: true },
}
2 changes: 0 additions & 2 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { type RequestHandler, createRequestHandler } from '@remix-run/architect'
import * as build from '@remix-run/dev/server-build'
import { installGlobals } from '@remix-run/node'
import { type APIGatewayProxyStructuredResultV2 } from 'aws-lambda'
import sourceMapSupport from 'source-map-support'

sourceMapSupport.install()
installGlobals({ nativeFetch: true })

const remixHandler = createRequestHandler({
build,
Expand Down

0 comments on commit 5290626

Please sign in to comment.