crowdsecurity/crowdsec · error

esbuild returned no output files

Error message

esbuild returned no output files

What it means

In pkg/appsec/challenge/js/cmd/bundle, the build step runs esbuild API compilation; if esbuild reports success but returns zero output files, the tool has nothing to write and fails with this error. This is an invariant violation — a successful build should always produce at least one output file (the JS bundle).

Source

Thrown at pkg/appsec/challenge/js/cmd/bundle/main.go:60

		Write:             false,
		Format:            t.format,
		Platform:          esbuildapi.PlatformBrowser,
		Target:            esbuildapi.ES2022,
		MinifyWhitespace:  true,
		MinifyIdentifiers: true,
		MinifySyntax:      true,
		Sourcemap:         esbuildapi.SourceMapNone,
	})

	if len(result.Errors) > 0 {
		for _, msg := range result.Errors {
			fmt.Fprintln(os.Stderr, msg.Text)
		}
		return fmt.Errorf("esbuild failed with %d error(s)", len(result.Errors))
	}

	if len(result.OutputFiles) == 0 {
		return errors.New("esbuild returned no output files")
	}

	if err := os.WriteFile(t.outFile, result.OutputFiles[0].Contents, 0o644); err != nil {
		return fmt.Errorf("write %s: %w", t.outFile, err)
	}

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the esbuild options in main.go: verify entryPoints, outfile, bundle and write:false are set so OutputFiles is populated.
  2. Check the esbuild library version for behavioral changes in OutputFiles and pin/upgrade accordingly.
  3. Log result.OutputFiles contents on failure to see if a plugin filtered them out.
  4. Review custom plugins/loaders for swallowed output.

Example fix

// before: no diagnostics
if len(result.OutputFiles) == 0 {
    return errors.New("esbuild returned no output files")
}
// after: surface config for debugging
if len(result.OutputFiles) == 0 {
    return fmt.Errorf("esbuild returned no output files (entry=%v outfile=%s)", opts.EntryPoints, t.outFile)
}
Defensive patterns

Strategy: validation

Validate before calling

// assert esbuild options produce output before building
if len(opts.EntryPoints) == 0 || opts.Outfile == "" {
    return errors.New("esbuild options missing entryPoints/outfile")
}
if !opts.Write == false { /* ensure write:false for in-memory builds */ }

Try / catch

result, err := api.Build(opts)
if err != nil { return err }
if len(result.Errors) > 0 { /* handle build errors */ }
if len(result.OutputFiles) == 0 {
    return fmt.Errorf("esbuild returned no output files (entry=%v outfile=%s)", opts.EntryPoints, opts.Outfile)
}

Prevention

When it happens

Trigger: esbuild.Build (or Build with write:false) completes with no errors but result.OutputFiles is empty in build(), called from main.

Common situations: A misconfigured bundle entrypoint or outfile setting; an esbuild API version change changing OutputFiles semantics; plugin/loader config that silently discards output; an empty entrypoint pipeline that esbuild treats as no-op.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/248e62246a462b37. Report an issue: GitHub.