From cdbf9ba73077e65e86c5a3195cec55e9fe8576f6 Mon Sep 17 00:00:00 2001 From: KevIsDev Date: Wed, 2 Apr 2025 21:38:50 +0100 Subject: [PATCH] refactor: update node polyfills and add buffer-polyfill plugin Modify the node polyfills configuration to include additional modules and add a new buffer-polyfill plugin to handle Buffer imports in env.mjs files. This change ensures compatibility with required Node.js modules in the Vite environment. --- vite.config.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index d6cc7156..60ea52bf 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -96,8 +96,28 @@ export default defineConfig((config) => { }, plugins: [ nodePolyfills({ - include: ['path', 'buffer', 'process'], + include: ['buffer', 'process', 'util', 'stream'], + globals: { + Buffer: true, + process: true, + global: true, + }, + protocolImports: true, + exclude: ['child_process', 'fs', 'path'], }), + { + name: 'buffer-polyfill', + transform(code, id) { + if (id.includes('env.mjs')) { + return { + code: `import { Buffer } from 'buffer';\n${code}`, + map: null, + }; + } + + return null; + }, + }, config.mode !== 'test' && remixCloudflareDevProxy(), remixVitePlugin({ future: {