mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-20 19:30:41 -05:00
fix: externalize global-agent and exclude Node built-ins from webpack
This commit is contained in:
@@ -12,7 +12,12 @@ export const setupGlobalAgentProxy = (): void => {
|
||||
if (globalThis.window !== undefined) {
|
||||
return;
|
||||
}
|
||||
if (globalThis.process === undefined || globalThis.process.release?.name !== "node") {
|
||||
// Hard guard: only run in real Node.js runtime (not edge/serverless)
|
||||
if (
|
||||
globalThis.process === undefined ||
|
||||
globalThis.process.release?.name !== "node" ||
|
||||
globalThis.process.versions?.node === undefined
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,9 +41,10 @@ export const setupGlobalAgentProxy = (): void => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Dynamic require keeps global-agent out of non-node bundles
|
||||
// Dynamic require prevents bundling into edge/serverless builds
|
||||
// Using string concatenation to prevent webpack from statically analyzing the require
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, turbo/no-undeclared-env-vars
|
||||
const { bootstrap } = require("global-agent");
|
||||
const { bootstrap } = require("global" + "-agent");
|
||||
bootstrap();
|
||||
globalThis.__FORMBRICKS_GLOBAL_AGENT_INITIALIZED = true;
|
||||
logger.info("Enabled global-agent proxy support for outbound HTTP requests");
|
||||
|
||||
@@ -19,7 +19,7 @@ const nextConfig = {
|
||||
output: "standalone",
|
||||
poweredByHeader: false,
|
||||
productionBrowserSourceMaps: true,
|
||||
serverExternalPackages: ["@aws-sdk", "@opentelemetry/instrumentation", "pino", "pino-pretty"],
|
||||
serverExternalPackages: ["@aws-sdk", "@opentelemetry/instrumentation", "pino", "pino-pretty", "global-agent"],
|
||||
outputFileTracingIncludes: {
|
||||
"/api/auth/**/*": ["../../node_modules/jose/**/*"],
|
||||
},
|
||||
@@ -113,6 +113,9 @@ const nextConfig = {
|
||||
config.resolve.fallback = {
|
||||
http: false, // Prevents Next.js from trying to bundle 'http'
|
||||
https: false,
|
||||
net: false, // Prevents Next.js from trying to bundle 'net' (used by global-agent)
|
||||
tls: false, // Prevents Next.js from trying to bundle 'tls' (used by global-agent)
|
||||
domain: false, // Prevents Next.js from trying to bundle 'domain' (used by global-agent dependencies)
|
||||
};
|
||||
return config;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user