{"id":"e2921287b6b422ba","repo":"gohugoio/hugo","slug":"npm-pack-failed-to-open-package-file-w","errorCode":null,"errorMessage":"npm pack: failed to open package file: %w","messagePattern":"npm pack: failed to open package file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/npm/package_builder.go","lineNumber":168,"sourceCode":"\t\t\treturn nil\n\t\t},\n\t})\n\tif err := w.Walk(); err != nil {\n\t\treturn err\n\t}\n\n\t// Process collected entries: for each module, prefer package.hugo.json\n\t// over package.json at the root level. Workspace package.json files are always processed.\n\tfor _, e := range entries {\n\t\tm := e.info.Meta()\n\t\t// Skip root-level package.json if this module has package.hugo.json.\n\t\tif !e.isHugoJSON && e.isRootLevel && modulesWithHugoJSON[m.ModulePath()] {\n\t\t\tcontinue\n\t\t}\n\n\t\tf, err := m.Open()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"npm pack: failed to open package file: %w\", err)\n\t\t}\n\t\tb.Add(m.ModulePath(), f)\n\t\tf.Close()\n\t}\n\n\tif b.Err() != nil {\n\t\treturn fmt.Errorf(\"npm pack: failed to build: %w\", b.Err())\n\t}\n\n\t// 4. Build the autogenerated workspace package.json.\n\t// Exclude deps already defined by the project itself — they don't\n\t// need to be duplicated in the workspace and it simplifies maintenance.\n\tmoduleDeps := make(map[string]any)\n\tmoduleDepsComments := make(map[string]any)\n\tfor k, v := range b.dependencies {\n\t\tif b.dependenciesComments[k] != \"project\" {\n\t\t\tmoduleDeps[k] = v\n\t\t\tmoduleDepsComments[k] = b.dependenciesComments[k]","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/npm/package_builder.go#L150-L186","documentation":"While collecting package.json/package.hugo.json files from all mounted Hugo modules (walking the _jsconfig virtual folder), Hugo failed to open one of the discovered files via its filesystem metadata. This is an I/O failure on a file the walker just listed, so it usually indicates filesystem-level trouble rather than bad JSON.","triggerScenarios":"`hugo mod npm pack` walking module-mounted package files where `m.Open()` fails — the underlying file was deleted/renamed between listing and open, permissions deny reading, or a broken symlink/vendored module path resolves to nothing.","commonSituations":"A concurrent process (npm install, editor, watcher) rewriting package.json during packing; stale `_vendor` directory after modules changed; permission problems in the module cache (`hugo mod clean` targets); network/overlay filesystems dropping files.","solutions":["Re-run `hugo mod npm pack` — transient races with npm installs or editors often clear on retry.","Check permissions on the reported module's package.json and on the Hugo module cache; run `hugo mod clean` to refresh cached modules.","If using vendoring, re-run `hugo mod vendor` so `_vendor` matches current module versions.","Look for broken symlinks in themes/modules that mount package.json."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for _, p := range packageFiles {\n    if fi, err := os.Stat(p); err != nil || fi.IsDir() {\n        return fmt.Errorf(\"package.hugo.json missing or unreadable: %s\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := b.Build(); err != nil {\n    if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission) {\n        log.Fatalf(\"check that package.hugo.json exists and is readable in each module: %v\", err)\n    }\n    return err\n}","preventionTips":["Ensure each module contributing npm deps ships a readable package.hugo.json","Check file permissions after cloning modules in CI containers (umask issues)","Run `hugo mod npm pack` locally before relying on it in CI"],"tags":["hugo","npm-pack","filesystem","modules"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}