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
- Verify the file exists at assets/<path> exactly as spelled, including extension and case.
- Move the file into the assets directory if it's in static/ or elsewhere — inject only resolves through /assets.
- 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
- Verify each inject file exists in assets/ (resources.Get) before passing it to js.Build
- Check module mounts — an inject file in a Hugo module must be mounted into assets
- Spelling and case matter on Linux CI even if macOS resolves case-insensitively
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
- inject: absolute paths not supported, must be relative to /a
- invalid engine version: %q
- unsupported target: %v
- invalid loader: %q
- unsupported Media Type: %q
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/dad4df481493cbad.json.
Report an issue: GitHub ↗.