gohugoio/hugo · error

inject: file not found

Error message

inject: file %q not found

What it means

Returned when an Inject entry cannot be resolved by the assets filesystem resolver: assetsResolver.resolveComponent returned nil. The path was relative but no matching file (with or without common extensions) exists under any configured /assets root.

Solutions

  1. Confirm the file exists under one of your configured /assets directories.
  2. Use the exact filename including extension.
  3. Check that module mounts include the assets folder the file lives in.
  4. Verify filename case matches on case-sensitive filesystems.
Defensive patterns

Strategy: validation

Validate before calling

// Before Build, confirm each inject path resolves under the assets fs.
for _, p := range opts.Inject {
    if fi, err := assetsFs.Stat(p); err != nil || fi.IsDir() {
        return fmt.Errorf("inject file not found in /assets: %q", p)
    }
}

Prevention

When it happens

Trigger: Passing opts.Inject = []string{"shims.js"} when assets/shims.js does not exist. ResolveComponent also tries shims.ts, shims.tsx, shims.jsx, etc., so the file must be entirely absent.

Common situations: Typo in the inject path; file lives in a different asset folder not mounted by Hugo modules; file exists only in a module that isn't imported; case-sensitivity mismatch (works on macOS, fails on Linux).

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/dad4df481493cbad. Report an issue: GitHub.

Appendix: 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 52c9bd7908)