{"record":{"id":"1a4f1614ed2099d8","repo":"gohugoio/hugo","slug":"could-not-find-q-in-the-import-context","errorCode":null,"errorMessage":"could not find %q in the import context","messagePattern":"could not find %q in the import context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_transformers/tocss/dartsass/transform.go","lineNumber":248,"sourceCode":"\tfor _, namePattern := range namePatterns {\n\t\tif r := t.importContext.Get(path.Join(dir, fmt.Sprintf(namePattern, name))); r != nil {\n\t\t\treturn r\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (t importResolver) Load(url string) (godartsass.Import, error) {\n\tif subPath, ok := sass.HugoVarsSubPath(url); ok {\n\t\treturn godartsass.Import{\n\t\t\tContent: sass.CreateVarsStyleSheet(sass.TranspilerDart, sass.ResolveVars(t.vars, subPath)),\n\t\t}, nil\n\t}\n\n\tif strings.HasPrefix(url, dartSassImportContextPrefix) {\n\t\tr := t.resolveInImportContext(url)\n\t\tif r == nil {\n\t\t\treturn godartsass.Import{}, fmt.Errorf(\"could not find %q in the import context\", url)\n\t\t}\n\t\tcontent, err := resources.InternalResourceSourceContent(t.ctx, r)\n\t\treturn godartsass.Import{Content: content, SourceSyntax: sassSourceSyntax(url)}, err\n\t}\n\n\tfilename, _ := paths.UrlStringToFilename(url)\n\tb, err := afero.ReadFile(hugofs.Os, filename)\n\n\treturn godartsass.Import{Content: string(b), SourceSyntax: sassSourceSyntax(filename)}, err\n}\n\nfunc sassSourceSyntax(name string) godartsass.SourceSyntax {\n\tswitch {\n\tcase strings.HasSuffix(name, \".sass\"):\n\t\treturn godartsass.SourceSyntaxSASS\n\tcase strings.HasSuffix(name, \".css\"):\n\t\treturn godartsass.SourceSyntaxCSS\n\tdefault:","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource_transformers/tocss/dartsass/transform.go#L230-L266","documentation":"Returned by the Dart Sass importResolver.Load when a URL prefixed with dartSassImportContextPrefix cannot be matched to a resource via resolveInImportContext. The resolver tries the import context, then partial-style name patterns; if none return a resource it errors. This means an @use/@import inside SCSS references a Hugo resource that does not exist in the import context.","triggerScenarios":"A .scss file processed by css.Sass (dartsass) contains @use 'partials/foo' or @import 'hugo-vars' where the referenced resource is not registered in the transformation's import context (e.g. not present in assets/ or not reachable relative to the entry).","commonSituations":"Renaming/moving a SCSS partial without updating @use paths, omitting the leading underscore for a partial that only exists as _foo.scss, case mismatch, or referencing a resource outside the assets mount.","solutions":["Verify the imported path resolves under assets/ relative to the importing file; for partials remember Hugo also checks the _prefixed name.","Add the missing partial file to assets/ (with the correct _underscore convention) or fix the @use/@import URL.","Check assets module mounts in hugo.toml to ensure the partial's directory is mounted into assets/."],"exampleFix":"// before: main.scss\n@use 'partials/buttons'; // _buttons.scss missing\n\n// after\n@use 'partials/buttons'; // assets/scss/partials/_buttons.scss now exists","handlingStrategy":"validation","validationCode":"// Check that an @use/@import path resolves under assets before building.\nfunc scssImportExists(assetsDir, rel string) bool {\n    candidates := []string{rel, filepath.Join(filepath.Dir(rel), \"_\"+filepath.Base(rel))}\n    for _, c := range candidates {\n        for _, ext := range []string{\".scss\", \".sass\", \".css\"} {\n            if _, err := os.Stat(filepath.Join(assetsDir, c+ext)); err == nil { return true }\n        }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the _partial convention consistently for SCSS partials.","Mount all SCSS directories into assets/ via hugo.toml module mounts.","Lint @use/@import paths in CI against the assets tree."],"tags":["dart-sass","sass","import-resolution","partials","asset-pipeline"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}