{"id":"a0c4c559247e906b","repo":"gohugoio/hugo","slug":"failed-to-apply-mounts-for-project-w","errorCode":null,"errorMessage":"failed to apply mounts for project: %w","messagePattern":"failed to apply mounts for project: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/collect.go","lineNumber":370,"sourceCode":"\n\tif !moduleImport.IgnoreConfig {\n\t\tif err := c.applyThemeConfig(ma); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tif err := c.applyMounts(moduleImport, ma); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn ma, nil\n}\n\nfunc (c *collector) addAndRecurse(owner *moduleAdapter) error {\n\tmoduleConfig := owner.Config()\n\tif owner.projectMod {\n\t\tif err := c.applyMounts(Import{}, owner); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to apply mounts for project: %w\", err)\n\t\t}\n\t}\n\tseen := make(map[pathVersionKey]bool)\n\tfor _, moduleImport := range moduleConfig.Imports {\n\t\tif moduleImport.Disable {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Prevent cyclic references.\n\t\tif v := c.isPathSeen(moduleImport.Path, owner); v != nil && v != owner {\n\t\t\tcontinue\n\t\t}\n\n\t\ttc, err := c.getAndCreateModule(owner, moduleImport)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/collect.go#L352-L388","documentation":"In `collector.addAndRecurse` (modules/collect.go:370), before recursing into imports, Hugo applies the project's own mount configuration (`module.mounts` mapping source dirs to content/assets/layouts etc.). If `applyMounts` fails for the project module, the error is wrapped as `failed to apply mounts for project`. The wrapped cause typically comes from validating mounts or scanning the project dir for JS config files.","triggerScenarios":"`applyMounts(Import{}, owner)` failing on the project module during collection: invalid `module.mounts` entries (empty source/target, disallowed target root), or failure opening/reading the project directory when auto-mounting common JS configs (postcss/babel/tailwind config detection).","commonSituations":"Hand-written `[[module.mounts]]` blocks with a typo'd or unsupported `target` (must start with content/assets/layouts/static/data/i18n/archetypes); a source path with wrong type; project directory permission problems; defining one mount and unintentionally dropping defaults, then referencing invalid entries.","solutions":["Inspect the wrapped inner error text — it names the invalid mount or unreadable path.","Validate each `[[module.mounts]]`: `source` must exist relative to the project, `target` must begin with a valid component root (content, assets, layouts, static, data, i18n, archetypes).","Remember that specifying any mounts for a component replaces the defaults — re-add defaults you still need.","Check read permissions on the project working directory."],"exampleFix":"# before\n[[module.mounts]]\nsource = \"src/content\"\ntarget = \"contents\"   # invalid target root\n# after\n[[module.mounts]]\nsource = \"src/content\"\ntarget = \"content\"","handlingStrategy":"try-catch","validationCode":"// Validate mount config shape before build: source/target both non-empty,\n// target rooted in a known component (content, layouts, static, assets, ...)","typeGuard":null,"tryCatchPattern":"if err := applyMounts(); err != nil {\n    // %w-wrapped: unwrap for root cause\n    log.Printf(\"project mounts failed: %v\", errors.Unwrap(err))\n    return err\n}","preventionTips":["Use errors.Unwrap/errors.Is on this wrapped error to get the underlying cause","Validate mount targets are one of Hugo's known component folders","Test mount config changes locally with `hugo mod graph` before pushing"],"tags":["hugo-modules","mounts","configuration"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}