[Vuejs]-How can I supress Vue/Webpack dev server proxy error messages in the terminal?

0👍

The workaround that I eventually settled on was intercepting process.stdout.write in the Javascript file that configured and ran the dev server/tests. Since our test command is implemented as a Vue CLI plugin, I could just put the override function in that plugin’s module.exports as follows:

module.exports = (api, options) => {
    api.registerCommand(
        'customTestCommand',
        {
            description: 'A test command for posting on Stack Overflow',
            usage: 'vue-cli-service customTestCommand [options]',
            options: {
                '--headless': 'run in headless mode without GUI'
                ...
            }
        },
        async (args, rawArgs) => {
            // Do other setup work here

            process.stdout.write = (function (write) {
                let clearBlankLine = false;

                return function (...args) {
                    const string = args[0];
                    const isProxyError = !!string.match(/Proxy error:|ECONNRESET/);
                    const hasContent = !!string.trim();

                    if (isProxyError) {
                        clearBlankLine = true;

                        return;
                    }

                    if (!clearBlankLine || hasContent) {
                        write.apply(process.stdout, args);
                    }

                    clearBlankLine = false;
                };
            }(process.stdout.write));

            // Wait to run your actual dev server process and test commands
            // Until here.
        }
    );
};

This maintains all coloring, spacing, history clearing, etc. on the command line output, but any line that has the terms Proxy Error or ECONNRESET are removed. You can customize the regex to your specific needs.

For a more detailed example of intercepting both stdout and stderr, as well as redirecting those outputs to different locations (e.g. files), see the following Github gist by Ben Buckman that inspired my solution: https://gist.github.com/benbuckman/2758563

0👍

You could add a filter at the top of the test, or globally in /cypress/support/index.js.

Cypress.on('window:before:load', window => {
  const originalConsoleLog = window.console.log;
  window.console.log = (msg) => {
    const isProxyError = msg.includes('ECONNRESET') || msg.startsWith('Proxy error:');
    if (!isProxyError) {
      originalConsoleLog(msg)
    }
  }
})

Leave a comment