Bun/Vite build failing in GitHub Actions/Ubuntu — “undefined” error message

When I run it on my Mac, bunx --bun vite build does this:

vite v5.4.2 building for production...
✓ 2951 modules transformed.
dist/index.html                     1.03 kB │ gzip:   0.56 kB
dist/assets/index-BifuYEoc.css     38.29 kB │ gzip:   8.03 kB
dist/assets/index-BG4aLjCM.js   3,571.02 kB │ gzip: 649.00 kB
✓ built in 3.08s

From a GitHub Actions workflow:

vite v5.4.2 building for production...
transforming...
✓ 347 modules transformed.
x Build failed in 3.12s
error during build:
undefined
error: script "build" exited with code 1
Error: Process completed with exit code 1.

undefined. That’s very helpful. Presumably, it’s the error message…

This used to work. The only thing I can think of that changed is I added vite.config.ts:

import path from "path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import graphqlLoader from "vite-plugin-graphql-loader";
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
  plugins: [react(), graphqlLoader(), tsconfigPaths()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    },
  }
});

How can I debug this?

To debug the build failure in GitHub Actions, follow these steps:

  1. Verify Configuration

Ensure that your vite.config.ts is properly set up:

Check Imports: Ensure that path, @vitejs/plugin-react, vite-plugin-graphql-loader, and vite-tsconfig-paths are correctly installed and imported.
Path Aliases: Confirm that @ alias resolves correctly to ./src.
  1. Add Verbose Logging

Increase the verbosity of the build process to get more detailed logs:

Modify your GitHub Actions workflow to include verbose logging:

yaml

- name: Build
  run: bunx --bun vite build --logLevel debug
  1. Check Node.js Version

Ensure that the Node.js version used in GitHub Actions matches the version on your local machine:

Specify Node.js version in your GitHub Actions workflow:

yaml

- name: Setup Node.js
  uses: actions/setup-node@v3
  with:
    node-version: '16.x'  # or the version you use locally
  1. Dependency Consistency

Ensure that dependencies are consistent between your local environment and the CI environment:

Run npm ci or yarn install --frozen-lockfile in GitHub Actions to ensure exact dependency versions.
  1. Simplify Configuration

Temporarily simplify your vite.config.ts to isolate the issue:

Comment out plugins one by one to see if the issue is related to a specific plugin:

ts

export default defineConfig({
  plugins: [react(), /* graphqlLoader(), tsconfigPaths() */],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    },
  }
});
  1. Revert Recent Changes

Since you mentioned that the build used to work, consider reverting to a previous version of your vite.config.ts to see if the issue is related to recent changes.
7. Check GitHub Actions Logs

Review the full build logs in GitHub Actions to see if there are additional clues:

Expand the logs for more detailed output.
Look for any additional error messages or stack traces that might provide more information.
  1. Test Locally with CI Configuration

Try to replicate the CI environment locally:

Use Docker or a similar environment to match the CI setup and test the build process.

By following these steps, you should be able to pinpoint and resolve the build issue. If the problem persists, provide additional log details or error messages for more targeted assistance.