{"record":{"id":"577f584c2e9fc7c3","repo":"gohugoio/hugo","slug":"failed-to-read-import-q-w","errorCode":null,"errorMessage":"failed to read import %q: %w","messagePattern":"failed to read import %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/batch.go","lineNumber":575,"sourceCode":"\t\t\t\t\tif resolved != nil {\n\t\t\t\t\t\tresolvePath := resources.InternalResourceTargetPath(resolved)\n\t\t\t\t\t\tdm.AddIdentity(identity.FirstIdentity(resolved))\n\t\t\t\t\t\timp := PrefixHugoVirtual + resolvePath\n\t\t\t\t\t\tstate.importResource.Set(imp, resolved)\n\t\t\t\t\t\tstate.importerImportContext.Set(imp, importContext)\n\t\t\t\t\t\treturn imp\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tImportOnLoadFunc: func(args api.OnLoadArgs) (string, error) {\n\t\t\t\timp := args.Path\n\n\t\t\t\tif r, found := state.importResource.Get(imp); found {\n\t\t\t\t\tcontent, err := resources.InternalResourceSourceContent(ctx, r)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn \"\", fmt.Errorf(\"failed to read import %q: %w\", resources.InternalResourceSourcePathBestEffort(r), err)\n\t\t\t\t\t}\n\t\t\t\t\treturn content, nil\n\t\t\t\t}\n\t\t\t\treturn \"\", nil\n\t\t\t},\n\t\t\tImportParamsOnLoadFunc: func(args api.OnLoadArgs) json.RawMessage {\n\t\t\t\tif importContext, found := state.importerImportContext.Get(args.Path); found {\n\t\t\t\t\tif !importContext.scriptOptions.IsZero() {\n\t\t\t\t\t\treturn importContext.scriptOptions.Params\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\tErrorMessageResolveFunc: func(args api.Message) *ErrorMessageResolved {\n\t\t\t\tif loc := args.Location; loc != nil {\n\t\t\t\t\tpath := strings.TrimPrefix(loc.File, NsHugoImportResolveFunc+\":\")\n\t\t\t\t\tif r, found := state.importResource.Get(path); found {\n\t\t\t\t\t\tsourcePath := resources.InternalResourceSourcePathBestEffort(r)","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/batch.go#L557-L593","documentation":"Thrown inside the batch build's ImportOnLoadFunc when resources.InternalResourceSourceContent fails to read the source content of a previously resolved import resource. The wrapped error reveals the underlying read failure (file missing, I/O error, or a stale cache entry pointing at a deleted source).","triggerScenarios":"During a js.Batcher build, an import that was successfully resolved and cached in state.importResource cannot have its source content read at esbuild load time. The resolve step succeeded but InternalResourceSourceContent(ctx, r) returned an error when esbuild asked for the bytes.","commonSituations":"Hugo server running while the asset file is renamed, moved, or deleted mid-build; resources/_gen cache pointing at a stale resource; permission denied on the source file; cross-platform path separator mismatches producing a path that no longer opens.","solutions":["Verify the asset file printed in the %q still exists at that path and is readable.","Restart `hugo server` to clear the in-memory importResource cache and re-resolve.","Delete the resources/_gen and _tmp directories to drop cached state, then rebuild.","Check filesystem permissions on the /assets tree."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Wrap the batch build call in error handling; on this specific error, log the import path from the wrapped error, clear the resources/_gen cache, and retry once. If it persists, surface the path to the user as a missing-asset diagnostic.","preventionTips":["Do not rename or delete /assets files while a build is running.","Commit asset files before triggering batch builds.","Keep Hugo's resource cache in sync: run hugo --gc periodically when assets churn."],"tags":["esbuild","assets","io","batch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}