gohugoio/hugo · error

inject: file %q not found

Error message

inject: file %q not found

What it means

After validating that an `inject` entry is relative, Hugo resolves it against the /assets component filesystem (including theme and module mounts). If no file matches, the js.Build call fails with this error naming the entry, because injecting a missing shim would silently change bundle behavior.

Source

Thrown at internal/js/esbuild/build.go:93

	var err error
	opts.compiled.Plugins, err = createBuildPlugins(c.rs, assetsResolver, dependencyManager, opts)
	if err != nil {
		return api.BuildResult{}, err
	}

	if opts.Inject != nil {
		// Resolve the absolute filenames.
		for i, ext := range opts.Inject {
			impPath := filepath.FromSlash(ext)
			if filepath.IsAbs(impPath) {
				return api.BuildResult{}, fmt.Errorf("inject: absolute paths not supported, must be relative to /assets")
			}

			m := assetsResolver.resolveComponent(impPath, false)

			if m == nil {
				return api.BuildResult{}, fmt.Errorf("inject: file %q not found", ext)
			}

			opts.Inject[i] = m.Filename

		}

		opts.compiled.Inject = opts.Inject

	}

	result := api.Build(opts.compiled)

	if len(result.Errors) > 0 {
		createErr := func(msg api.Message) error {
			if msg.Location == nil {
				return errors.New(msg.Text)
			}
			var (

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Verify the file exists at assets/<path> exactly as spelled, including extension and case.
  2. Move the file into the assets directory if it's in static/ or elsewhere — inject only resolves through /assets.
  3. If it comes from a module/theme, confirm the module is in the imports and its mount covers the file.

Example fix

{{/* before: file is at assets/shims/process.js */}}
{{ $opts := dict "inject" (slice "shim/process.js") }}
{{/* after */}}
{{ $opts := dict "inject" (slice "shims/process.js") }}
Defensive patterns

Strategy: validation

Validate before calling

{{ if not (resources.Get "js/shim.js") }}{{ errorf "missing inject file js/shim.js" }}{{ end }}

Prevention

When it happens

Trigger: `js.Build` with an `inject` entry whose path doesn't resolve via assetsResolver.resolveComponent — file absent from assets/ in the project, theme, and all module mounts, or the path/extension is misspelled.

Common situations: Typos in the inject path or wrong extension (.js vs .ts); the shim living in static/ or the project root instead of assets/; a theme providing the shim but the theme/module not being enabled; case-sensitivity differences between macOS dev and Linux CI.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/dad4df481493cbad.json. Report an issue: GitHub ↗.