gohugoio/hugo · error
npm pack: failed to open package file: %w
Error message
npm pack: failed to open package file: %w
What it means
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.
Source
Thrown at modules/npm/package_builder.go:168
return nil
},
})
if err := w.Walk(); err != nil {
return err
}
// Process collected entries: for each module, prefer package.hugo.json
// over package.json at the root level. Workspace package.json files are always processed.
for _, e := range entries {
m := e.info.Meta()
// Skip root-level package.json if this module has package.hugo.json.
if !e.isHugoJSON && e.isRootLevel && modulesWithHugoJSON[m.ModulePath()] {
continue
}
f, err := m.Open()
if err != nil {
return fmt.Errorf("npm pack: failed to open package file: %w", err)
}
b.Add(m.ModulePath(), f)
f.Close()
}
if b.Err() != nil {
return fmt.Errorf("npm pack: failed to build: %w", b.Err())
}
// 4. Build the autogenerated workspace package.json.
// Exclude deps already defined by the project itself — they don't
// need to be duplicated in the workspace and it simplifies maintenance.
moduleDeps := make(map[string]any)
moduleDepsComments := make(map[string]any)
for k, v := range b.dependencies {
if b.dependenciesComments[k] != "project" {
moduleDeps[k] = v
moduleDepsComments[k] = b.dependenciesComments[k]View on GitHub ↗ (pinned to 8a468df065)
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.
Defensive patterns
Strategy: validation
Validate before calling
for _, p := range packageFiles {
if fi, err := os.Stat(p); err != nil || fi.IsDir() {
return fmt.Errorf("package.hugo.json missing or unreadable: %s", p)
}
} Try / catch
if err := b.Build(); err != nil {
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, fs.ErrPermission) {
log.Fatalf("check that package.hugo.json exists and is readable in each module: %v", err)
}
return err
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- failed to vendor module: %w
- failed to copy module to vendor dir: %w
- failed to make target dir: %w
- failed to copy module file to vendor: %w
- failed to copy resources to vendor dir: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/e2921287b6b422ba.json.
Report an issue: GitHub ↗.