gohugoio/hugo · error
inject: absolute paths not supported, must be relative to…
Error message
inject: absolute paths not supported, must be relative to /assets
What it means
Returned when an entry in the Inject option is an absolute filesystem path. Hugo's js.Build Inject resolves files only relative to the /assets filesystem; absolute paths are explicitly rejected at build.go:87.
Solutions
- Strip the leading slash / drive letter so the path is relative to /assets.
- Use forward slashes (e.g. "js/shims.js").
Example fix
// before
{{ $opts := dict "inject" (slice "/abs/path/shims.js") }}
// after
{{ $opts := dict "inject" (slice "js/shims.js") }} Defensive patterns
Strategy: validation
Validate before calling
for _, p := range opts.Inject {
if filepath.IsAbs(filepath.FromSlash(p)) {
return fmt.Errorf("inject path must be relative to /assets: %q", p)
}
} Prevention
- Always express asset paths relative to /assets.
- Never join user input with a leading slash when constructing inject paths.
- Reject absolute paths at your config layer so the error surfaces before Build.
When it happens
Trigger: Passing opts.Inject containing a path that begins with / (or a Windows drive letter) to js.Build. filepath.IsAbs returns true and the build aborts before resolution is attempted.
Common situations: User copies a config from a raw Node/esbuild setup where absolute paths are normal; templating that joins paths produces a leading slash; environment-specific absolute paths in a shared config.
Related errors
- inject: file not found
- failed to compile cache buster target
- failed to marshal params
- failed to read import
- failed to read
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/a1021e946e97d08b.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/esbuild/build.go:87
return api.BuildResult{}, err
}
if err := opts.compile(); err != nil {
return api.BuildResult{}, err
}
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)
View on GitHub (pinned to 52c9bd7908)