{"record":{"id":"0590e4f24ddc0e02","repo":"gohugoio/hugo","slug":"importonloadfunc-failed-to-resolve-q","errorCode":null,"errorMessage":"ImportOnLoadFunc failed to resolve %q","messagePattern":"ImportOnLoadFunc failed to resolve %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/resolve.go","lineNumber":335,"sourceCode":"\t\t\t\t\tc := string(b)\n\n\t\t\t\t\treturn api.OnLoadResult{\n\t\t\t\t\t\t// See https://github.com/evanw/esbuild/issues/502\n\t\t\t\t\t\t// This allows all modules to resolve dependencies\n\t\t\t\t\t\t// in the main project's node_modules.\n\t\t\t\t\t\tResolveDir: opts.ResolveDir,\n\t\t\t\t\t\tContents:   &c,\n\t\t\t\t\t\tLoader:     opts.loaderFromFilename(args.Path),\n\t\t\t\t\t}, nil\n\t\t\t\t})\n\t\t\tbuild.OnLoad(api.OnLoadOptions{Filter: `.*`, Namespace: NsHugoImportResolveFunc},\n\t\t\t\tfunc(args api.OnLoadArgs) (api.OnLoadResult, error) {\n\t\t\t\t\tc, err := opts.ImportOnLoadFunc(args)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn api.OnLoadResult{}, err\n\t\t\t\t\t}\n\t\t\t\t\tif c == \"\" {\n\t\t\t\t\t\treturn api.OnLoadResult{}, fmt.Errorf(\"ImportOnLoadFunc failed to resolve %q\", args.Path)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn api.OnLoadResult{\n\t\t\t\t\t\tResolveDir: opts.ResolveDir,\n\t\t\t\t\t\tContents:   &c,\n\t\t\t\t\t\tLoader:     opts.loaderFromFilename(args.Path),\n\t\t\t\t\t}, nil\n\t\t\t\t})\n\t\t},\n\t}\n\n\tparams := opts.Params\n\tif params == nil {\n\t\t// This way @params will always resolve to something.\n\t\tparams = make(map[string]any)\n\t}\n\n\tb, err := json.Marshal(params)","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/resolve.go#L317-L353","documentation":"Returned when the ImportOnLoadFunc callback (used by js.Batcher to provide content for imports resolved via ImportOnResolveFunc into the ns-hugo-imp-func namespace) returns an empty string. The resolver previously claimed the path but the loader can't produce content.","triggerScenarios":"In a batch build, an import was routed via ImportOnResolveFunc to the NsHugoImportResolveFunc namespace, but at load time the corresponding ImportOnLoadFunc returns (\"\", nil) — no error, just no content. Typically state.importResource.Get(imp) returned not-found for a path that was supposed to be registered.","commonSituations":"Race between script option registration and import resolution; template provides an Import path that doesn't map back to a registered resource; custom batch option maps with mismatched keys; rename of a script mid-session leaving stale resolver state.","solutions":["Inspect the import path printed — verify it matches a registered script key.","Ensure every script option set on the batcher has a valid Resource.","Restart hugo server to clear stale import cache and re-register scripts."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before triggering a batch build, ensure every script option that will be\n// resolved via ImportOnResolveFunc also has a Resource that ImportOnLoadFunc\n// can read. Verify the import path key matches the registered script key.\nfor _, key := range registeredScriptKeys {\n    if _, ok := state.importResource.Get(key); !ok {\n        return fmt.Errorf(\"script %q registered but no resource attached\", key)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep script option keys and the Import paths your templates emit perfectly consistent.","Avoid renaming scripts while a Hugo server session is running.","Ensure every batch script has a non-nil Resource before building."],"tags":["esbuild","batch","resolve","template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}