diff --git a/.changeset/pretty-moose-flow.md b/.changeset/pretty-moose-flow.md new file mode 100644 index 00000000000..ea68673d50e --- /dev/null +++ b/.changeset/pretty-moose-flow.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +Polyfill Node `process` and `Buffer` globals when detected diff --git a/packages/remix-dev/compiler/js/compiler.ts b/packages/remix-dev/compiler/js/compiler.ts index b8c7b265752..7679e636873 100644 --- a/packages/remix-dev/compiler/js/compiler.ts +++ b/packages/remix-dev/compiler/js/compiler.ts @@ -1,7 +1,6 @@ import * as path from "path"; import { builtinModules as nodeBuiltins } from "module"; import * as esbuild from "esbuild"; -import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill"; import type { RemixConfig } from "../../config"; import { type Manifest } from "../../manifest"; @@ -12,6 +11,7 @@ import { cssFilePlugin } from "../plugins/cssImports"; import { absoluteCssUrlsPlugin } from "../plugins/absoluteCssUrlsPlugin"; import { deprecatedRemixPackagePlugin } from "../plugins/deprecatedRemixPackage"; import { emptyModulesPlugin } from "../plugins/emptyModules"; +import { nodePolyfillsPlugin } from "../plugins/nodePolyfillsPlugin"; import { mdxPlugin } from "../plugins/mdx"; import { externalPlugin } from "../plugins/external"; import { cssBundlePlugin } from "../plugins/cssBundlePlugin"; @@ -104,7 +104,7 @@ const createEsbuildConfig = ( emptyModulesPlugin(ctx, /^@remix-run\/(deno|cloudflare|node)(\/.*)?$/, { includeNodeModules: true, }), - nodeModulesPolyfillPlugin(), + nodePolyfillsPlugin(), externalPlugin(/^node:.*/, { sideEffects: false }), ]; diff --git a/packages/remix-dev/compiler/plugins/nodePolyfillsPlugin.ts b/packages/remix-dev/compiler/plugins/nodePolyfillsPlugin.ts new file mode 100644 index 00000000000..c9557a9e835 --- /dev/null +++ b/packages/remix-dev/compiler/plugins/nodePolyfillsPlugin.ts @@ -0,0 +1,11 @@ +import type { Plugin } from "esbuild"; +import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill"; + +export function nodePolyfillsPlugin(): Plugin { + return nodeModulesPolyfillPlugin({ + globals: { + Buffer: true, + process: true, + }, + }); +} diff --git a/packages/remix-dev/compiler/server/compiler.ts b/packages/remix-dev/compiler/server/compiler.ts index 4fb76bdad2d..f1fb0c0d491 100644 --- a/packages/remix-dev/compiler/server/compiler.ts +++ b/packages/remix-dev/compiler/server/compiler.ts @@ -1,5 +1,4 @@ import * as esbuild from "esbuild"; -import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill"; import { type Manifest } from "../../manifest"; import { loaders } from "../utils/loaders"; @@ -10,6 +9,7 @@ import { cssFilePlugin } from "../plugins/cssImports"; import { absoluteCssUrlsPlugin } from "../plugins/absoluteCssUrlsPlugin"; import { deprecatedRemixPackagePlugin } from "../plugins/deprecatedRemixPackage"; import { emptyModulesPlugin } from "../plugins/emptyModules"; +import { nodePolyfillsPlugin } from "../plugins/nodePolyfillsPlugin"; import { mdxPlugin } from "../plugins/mdx"; import { serverAssetsManifestPlugin } from "./plugins/manifest"; import { serverBareModulesPlugin } from "./plugins/bareImports"; @@ -67,7 +67,7 @@ const createEsbuildConfig = ( ]; if (ctx.config.serverPlatform !== "node") { - plugins.unshift(nodeModulesPolyfillPlugin()); + plugins.unshift(nodePolyfillsPlugin()); } return { diff --git a/packages/remix-dev/package.json b/packages/remix-dev/package.json index c0948cdc021..6dc8166f5ab 100644 --- a/packages/remix-dev/package.json +++ b/packages/remix-dev/package.json @@ -36,7 +36,7 @@ "chokidar": "^3.5.1", "dotenv": "^16.0.0", "esbuild": "0.17.6", - "esbuild-plugins-node-modules-polyfill": "^1.0.16", + "esbuild-plugins-node-modules-polyfill": "^1.1.0", "execa": "5.1.1", "exit-hook": "2.2.1", "express": "^4.17.1", diff --git a/yarn.lock b/yarn.lock index 728c688b74e..9d8a3b185f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2688,7 +2688,7 @@ estree-walker "^2.0.1" picomatch "^2.2.2" -"@rollup/pluginutils@^5.0.1", "@rollup/pluginutils@^5.0.2": +"@rollup/pluginutils@^5.0.1": version "5.0.2" resolved "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz#012b8f53c71e4f6f9cb317e311df1404f56e7a33" integrity sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA== @@ -6132,12 +6132,14 @@ esbuild-openbsd-64@0.14.47: resolved "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.47.tgz#309af806db561aa886c445344d1aacab850dbdc5" integrity sha512-QpgN8ofL7B9z8g5zZqJE+eFvD1LehRlxr25PBkjyyasakm4599iroUpaj96rdqRlO2ShuyqwJdr+oNqWwTUmQw== -esbuild-plugins-node-modules-polyfill@^1.0.16: - version "1.0.16" - resolved "https://registry.npmjs.org/esbuild-plugins-node-modules-polyfill/-/esbuild-plugins-node-modules-polyfill-1.0.16.tgz#c904592749efcd185df0245f9f9386ee0b371f4f" - integrity sha512-l2kfXhuqez0HnmzDjUh1y4fwDjAP8f2nW3u145AGp8kz7tQkgVKUb4yWeKbMJvbsHcpyMzguCOkOJD/+6SGvZw== +esbuild-plugins-node-modules-polyfill@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/esbuild-plugins-node-modules-polyfill/-/esbuild-plugins-node-modules-polyfill-1.1.0.tgz#9b701b0bff618ce24ac262fd49aa49dd3da58197" + integrity sha512-pfJAbt00Luc9uuYtXGlaUrcTzf4h95Cr9Lfw+7smTFmZWtbwbrN5Hsf+La4lfD6OygHvZeefZFILOGK1ZnuyjA== dependencies: - modern-node-polyfills "^1.0.0" + "@jspm/core" "^2.0.1" + local-pkg "^0.4.3" + resolve.exports "^2.0.2" esbuild-register@^3.3.2: version "3.3.2" @@ -10212,15 +10214,6 @@ mlly@^1.0.0, mlly@^1.1.0: pkg-types "^1.0.1" ufo "^1.0.1" -modern-node-polyfills@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/modern-node-polyfills/-/modern-node-polyfills-1.0.0.tgz#f0ac8eddb49dd18f51a9f6e72d2934392bbc9720" - integrity sha512-w1yb6ae5qSUJJ2u41krkUAxs+L7i9143Qam8EuXwDMeZHxl1JN8RfTSXG4S2bt0RHIRMeoWm/HCeO0pNIHmIYQ== - dependencies: - "@jspm/core" "^2.0.1" - "@rollup/pluginutils" "^5.0.2" - local-pkg "^0.4.3" - morgan@^1.10.0: version "1.10.0" resolved "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz" @@ -11827,6 +11820,11 @@ resolve.exports@^1.1.0: resolved "https://registry.npmjs.org/resolve.exports/-/resolve.exports-1.1.0.tgz" integrity sha512-J1l+Zxxp4XK3LUDZ9m60LRJF/mAe4z6a4xyabPHk7pvK5t35dACV32iIjJDFeWZFfZlO29w6SZ67knR0tHzJtQ== +resolve.exports@^2.0.2: + version "2.0.2" + resolved "https://registry.npmjs.org/resolve.exports/-/resolve.exports-2.0.2.tgz#f8c934b8e6a13f539e38b7098e2e36134f01e800" + integrity sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg== + resolve@^1.1.6, resolve@^1.10.0, resolve@^1.10.1, resolve@^1.14.2, resolve@^1.19.0, resolve@^1.20.0: version "1.22.0" resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz"