{"record":{"id":"a1021e946e97d08b","repo":"gohugoio/hugo","slug":"inject-absolute-paths-not-supported-must-be-rela","errorCode":null,"errorMessage":"inject: absolute paths not supported, must be relative to /assets","messagePattern":"inject: absolute paths not supported, must be relative to /assets","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/build.go","lineNumber":87,"sourceCode":"\t\treturn api.BuildResult{}, err\n\t}\n\n\tif err := opts.compile(); err != nil {\n\t\treturn api.BuildResult{}, err\n\t}\n\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","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/build.go#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Strip the leading slash / drive letter so the path is relative to /assets.","Use forward slashes (e.g. \"js/shims.js\")."],"exampleFix":"// before\n{{ $opts := dict \"inject\" (slice \"/abs/path/shims.js\") }}\n\n// after\n{{ $opts := dict \"inject\" (slice \"js/shims.js\") }}","handlingStrategy":"validation","validationCode":"for _, p := range opts.Inject {\n    if filepath.IsAbs(filepath.FromSlash(p)) {\n        return fmt.Errorf(\"inject path must be relative to /assets: %q\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["esbuild","inject","assets","config"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}