{"record":{"id":"318395944fd396dc","repo":"gohugoio/hugo","slug":"npm-pack-failed-to-parse-s-w","errorCode":null,"errorMessage":"npm pack: failed to parse %s: %w","messagePattern":"npm pack: failed to parse (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/npm/package_builder.go","lineNumber":83,"sourceCode":"\tskipPackageJSON := buildSkipPackageJSON(mods)\n\n\t// 1. Read project deps: prefer package.hugo.json, fall back to package.json.\n\tvar rootPkg map[string]any\n\trootData, err := afero.ReadFile(sourceFs, packageJSONName)\n\tif err == nil {\n\t\trootPkg = b.unmarshal(bytes.NewReader(rootData))\n\t\tif b.err != nil {\n\t\t\treturn fmt.Errorf(\"npm pack: failed to parse package.json: %w\", b.err)\n\t\t}\n\t}\n\n\t// Workspaces source: prefer package.hugo.json, fall back to package.json.\n\tvar workspacesSource map[string]any\n\thugoData, hugoErr := afero.ReadFile(sourceFs, files.FilenamePackageHugoJSON)\n\tif hugoErr == nil {\n\t\thugoPkg := b.unmarshal(bytes.NewReader(hugoData))\n\t\tif b.err != nil {\n\t\t\treturn fmt.Errorf(\"npm pack: failed to parse %s: %w\", files.FilenamePackageHugoJSON, b.err)\n\t\t}\n\t\tb.addm(\"project\", hugoPkg)\n\t\tworkspacesSource = hugoPkg\n\t} else if rootPkg != nil {\n\t\tb.addm(\"project\", rootPkg)\n\t\tworkspacesSource = rootPkg\n\t}\n\n\t// 2. Read deps from referenced workspaces (always from package.json).\n\tfor _, wsDir := range resolveProjectWorkspaces(sourceFs, workspacesSource, workspacePath) {\n\t\twsFile := filepath.Join(wsDir, packageJSONName)\n\t\twsData, err := afero.ReadFile(sourceFs, wsFile)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\twsm := b.unmarshal(bytes.NewReader(wsData))\n\t\tif b.err != nil {\n\t\t\treturn fmt.Errorf(\"npm pack: failed to parse %s: %w\", wsFile, b.err)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/npm/package_builder.go#L65-L101","documentation":"In npm.Pack (modules/npm/package_builder.go:83). When package.hugo.json (files.FilenamePackageHugoJSON) is present it is parsed preferentially; a JSON parse failure is wrapped with the filename. package.hugo.json is the Hugo-flavored package descriptor that lets modules declare npm dependencies.","triggerScenarios":"A package.hugo.json file exists in the project root but contains invalid JSON.","commonSituations":"Hand-authoring package.hugo.json with syntax errors; partial git checkout; merging a theme's package.hugo.json incorrectly; converting from package.json and leaving invalid structure.","solutions":["Run the file through a JSON validator and fix the reported location.","Compare against a known-good package.hugo.json (same shape as package.json: dependencies, devDependencies, workspaces).","Delete package.hugo.json if you do not need Hugo-specific package merging (Hugo falls back to package.json)."],"exampleFix":"// before: package.hugo.json\n{\n  dependencies: { \"jquery\": \"^3.0\" } // unquoted key\n}\n\n// after\n{\n  \"dependencies\": { \"jquery\": \"^3.0\" }\n}","handlingStrategy":"validation","validationCode":"if data, err := os.ReadFile(\"package.hugo.json\"); err == nil {\n    var v any\n    if err := json.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"package.hugo.json invalid: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat package.hugo.json as strict JSON (no comments/trailing commas).","Delete it if unused; Hugo falls back to package.json.","Validate in CI alongside package.json."],"tags":["hugo","npm-pack","json"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}