Skip to content

Commit

Permalink
add builtin node modules to webpack externals
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 24, 2024
1 parent 8079753 commit cea2129
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 cea2129

Please sign in to comment.