{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/npm/package_builder.go#L150-L186","documentation":"In npm.Pack (modules/npm/package_builder.go:168). While walking the _jsconfig virtual filesystem for module package files, for each collected entry it calls m.Open(); if the underlying file cannot be opened the error is wrapped. This operates on the Hugo virtual fs that merges all module mounts, so the failure is at the file-open layer.","triggerScenarios":"A module's mounted package.json/package.hugo.json entry exists in the virtual filesystem metadata but the backing file cannot be opened (permissions, broken symlink, race with file deletion, or a mount pointing to a removed path).","commonSituations":"A theme module mount referencing a package file that was deleted upstream; file permission issues in the module cache; symlinks in the module cache pointing nowhere; concurrent file changes during 'hugo server'.","solutions":["Run 'hugo mod clean' then 'hugo mod tidy' to refresh the module cache.","Check the mount source path in the offending module/theme actually exists and is readable.","Remove or fix mounts that point at deleted package files."],"exampleFix":"// before\n[[module.mounts]]\nsource = \"node_modules/pkg/package.json\"\ntarget = \"_jsconfig/package.json\"\n// file missing on disk -> error\n\n// after: ensure the source exists, or drop the mount\n// (run `npm install` first, or remove the stale mount)","handlingStrategy":"validation","validationCode":"// verify each mounted package file is openable before building\nfor _, m := range cfg.Module.Mounts {\n    if base := filepath.Base(m.Source); base == \"package.json\" || base == \"package.hugo.json\" {\n        full := filepath.Join(workDir, m.Source)\n        if f, err := os.Open(full); err != nil {\n            return fmt.Errorf(\"mount source %s not openable: %w\", full, err)\n        } else { f.Close() }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep module mounts pointing at real, readable files.","Run 'hugo mod clean' / 'hugo mod tidy' when modules change.","Avoid deleting files under a live 'hugo server'."],"tags":["hugo","npm-pack","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}