{"id":"dad4df481493cbad","repo":"gohugoio/hugo","slug":"inject-file-q-not-found","errorCode":null,"errorMessage":"inject: file %q not found","messagePattern":"inject: file %q not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/build.go","lineNumber":93,"sourceCode":"\n\tvar err error\n\topts.compiled.Plugins, err = createBuildPlugins(c.rs, assetsResolver, dependencyManager, opts)\n\tif err != nil {\n\t\treturn api.BuildResult{}, err\n\t}\n\n\tif opts.Inject != nil {\n\t\t// Resolve the absolute filenames.\n\t\tfor i, ext := range opts.Inject {\n\t\t\timpPath := filepath.FromSlash(ext)\n\t\t\tif filepath.IsAbs(impPath) {\n\t\t\t\treturn api.BuildResult{}, fmt.Errorf(\"inject: absolute paths not supported, must be relative to /assets\")\n\t\t\t}\n\n\t\t\tm := assetsResolver.resolveComponent(impPath, false)\n\n\t\t\tif m == nil {\n\t\t\t\treturn api.BuildResult{}, fmt.Errorf(\"inject: file %q not found\", ext)\n\t\t\t}\n\n\t\t\topts.Inject[i] = m.Filename\n\n\t\t}\n\n\t\topts.compiled.Inject = opts.Inject\n\n\t}\n\n\tresult := api.Build(opts.compiled)\n\n\tif len(result.Errors) > 0 {\n\t\tcreateErr := func(msg api.Message) error {\n\t\t\tif msg.Location == nil {\n\t\t\t\treturn errors.New(msg.Text)\n\t\t\t}\n\t\t\tvar (","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/build.go#L75-L111","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"{{/* before: file is at assets/shims/process.js */}}\n{{ $opts := dict \"inject\" (slice \"shim/process.js\") }}\n{{/* after */}}\n{{ $opts := dict \"inject\" (slice \"shims/process.js\") }}","handlingStrategy":"validation","validationCode":"{{ if not (resources.Get \"js/shim.js\") }}{{ errorf \"missing inject file js/shim.js\" }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hugo","js-build","esbuild","assets"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}