coleam00 / bolt.new-any-llm

Prompt, run, edit, and deploy full-stack web applications using any LLM you want!
https://bolt.new
MIT License
4.65k stars 1.92k forks source link

Proxy Error #415

Open axil76 opened 6 days ago

axil76 commented 6 days ago

Hello,

I use a proxy and when I run "pnpm run dev", I get an error

"Proxy environment variables detected. We'll use your proxy for fetch requests. Error: write EPIPE at afterWriteDispatched (node:internal/stream_base_commons:159:15) at writeGeneric (node:internal/stream_base_commons:150:3) at Socket._writeGeneric (node:net:957:11) at Socket._write (node:net:969:8) at writeOrBuffer (node:internal/streams/writable:572:12) at _write (node:internal/streams/writable:501:10) at Writable.write (node:internal/streams/writable:510:10) ..... /run.js:271:7 ) { errno: -32, code: 'EPIPE', syscall: 'write' } ELIFECYCLE  Command failed with exit code 1."

Can we enable more tracing to see where the problem is

Thanks

SujalXplores commented 6 days ago

@axil76 I'll help you debug this proxy-related EPIPE error. Looking at the codebase, we can enable more detailed logging in a few ways:

  1. First, let's set the debug level to trace in your .env.local file:
VITE_LOG_LEVEL=trace
  1. Looking at the logger implementation in the codebase:
export type DebugLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';

type LoggerFunction = (...messages: any[]) => void;

interface Logger {
  trace: LoggerFunction;
  debug: LoggerFunction;
  info: LoggerFunction;
  warn: LoggerFunction;
  error: LoggerFunction;
  setLevel: (level: DebugLevel) => void;
}

let currentLevel: DebugLevel = (import.meta.env.VITE_LOG_LEVEL ?? import.meta.env.DEV) ? 'debug' : 'info';

We can see that the logging level is controlled by the VITE_LOG_LEVEL environment variable.

  1. For network-related issues, we should also look at the fetch implementation:
type CommonRequest = Omit<RequestInit, 'body'> & { body?: URLSearchParams };

export async function request(url: string, init?: CommonRequest) {
  if (import.meta.env.DEV) {
    const nodeFetch = await import('node-fetch');
    const https = await import('node:https');

    const agent = url.startsWith('https') ? new https.Agent({ rejectUnauthorized: false }) : undefined;

    return nodeFetch.default(url, { ...init, agent });
  }

  return fetch(url, init);
}

To add more debugging for proxy-related issues, let's modify this file to include more logging. Create a new file called fetch.debug.ts in the same directory with this content:

import { createScopedLogger } from '~/utils/logger';

const logger = createScopedLogger('fetch');

type CommonRequest = Omit<RequestInit, 'body'> & { body?: URLSearchParams };

export async function request(url: string, init?: CommonRequest) {
  if (import.meta.env.DEV) {
    const nodeFetch = await import('node-fetch');
    const https = await import('node:https');

    // Log proxy environment variables
    logger.debug('Proxy environment variables:', {
      http_proxy: process.env.http_proxy,
      HTTP_PROXY: process.env.HTTP_PROXY,
      https_proxy: process.env.https_proxy,
      HTTPS_PROXY: process.env.HTTPS_PROXY,
      no_proxy: process.env.no_proxy,
      NO_PROXY: process.env.NO_PROXY
    });

    const agent = url.startsWith('https') 
      ? new https.Agent({ 
          rejectUnauthorized: false,
          keepAlive: true,
          timeout: 60000
        }) 
      : undefined;

    logger.debug(`Making request to: ${url}`);
    try {
      const response = await nodeFetch.default(url, { ...init, agent });
      logger.debug(`Response status: ${response.status}`);
      return response;
    } catch (error) {
      logger.error('Fetch error:', error);
      throw error;
    }
  }

  return fetch(url, init);
}
  1. Update your vite.config.ts to include proxy debugging:
import { defineConfig } from 'vite';

export default defineConfig({
  // ... 
  server: {
    proxy: {
      // Log proxy config
      configure: (proxy, options) => {
        console.log('Vite proxy configuration:', options);
      }
    }
  }
});
  1. You can run the dev server with additional Node debugging flags:
NODE_DEBUG=http,net,stream pnpm run dev

This will give you much more detailed logging about:

The EPIPE error typically occurs when the remote end of a connection is closed while we're still trying to write to it. With these debugging changes, you should be able to see exactly where in the request/response cycle this is happening.

Let me know what the logs show with these changes and we can further diagnose the issue.