Skip to content

Commit

Permalink
add missing node modules to externals (#70382)
Browse files Browse the repository at this point in the history
We should not attempt to bundle builtin node modules on the server. This
adds modules provided by Node.js to our externals list (along with some
missing internal ones in Turbopack. These were copied from
[here](https://github.com/vercel/next.js/blob/a675bde6c738318264573144663e38819aeb2661/crates/next-custom-transforms/src/transforms/warn_for_edge_runtime.rs#L77-L89)).

Fixes #70262
Closes NDX-314
  • Loading branch information
ztanner authored Sep 24, 2024
1 parent fdbb09f commit 12e5863
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ export default async function getBaseWebpackConfig(

const aliasCodeConditionTest = [codeCondition.test, pageExtensionsRegex]

const builtinModules = require('module').builtinModules

let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
...(isNodeServer ? { externalsPresets: { node: true } } : {}),
Expand All @@ -856,6 +858,7 @@ export default async function getBaseWebpackConfig(
: []),
]
: [
...builtinModules,
({
context,
request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import timers from 'timers'
import tty from 'tty'
import util from 'util'
import zlib from 'zlib'

import '_http_common'
import 'setimmediate'

async function getData() {
Expand Down
14 changes: 13 additions & 1 deletion turbopack/crates/turbopack-resolve/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
typescript::{apply_tsconfig_resolve_options, tsconfig, tsconfig_resolve_options},
};

const NODE_EXTERNALS: [&str; 51] = [
const NODE_EXTERNALS: [&str; 63] = [
"assert",
"async_hooks",
"buffer",
Expand Down Expand Up @@ -67,6 +67,18 @@ const NODE_EXTERNALS: [&str; 51] = [
"worker_threads",
"zlib",
"pnpapi",
"_http_agent",
"_http_client",
"_http_common",
"_http_incoming",
"_http_outgoing",
"_http_server",
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_wrap",
"_stream_writable",
];

const EDGE_NODE_EXTERNALS: [&str; 5] = ["buffer", "events", "assert", "util", "async_hooks"];
Expand Down

0 comments on commit 12e5863

Please sign in to comment.