pulumi/pulumi · error
error running %s: %w, output: %s
Error message
error running %s: %w, output: %s
What it means
This error is returned by npmManager.Link when `npm pkg get allowScripts` fails while reading the existing allowScripts allowlist. Link needs the current allowScripts map so it can add the local file: dependency to it. The wrapped output shows the combined npm output for debugging.
Source
Thrown at sdk/nodejs/npm/npm.go:111
func (node *npmManager) Link(ctx context.Context, dir, packageName, path string) error {
packageSpecifier := getLinkPackageProperty(packageName, path)
cmd := exec.CommandContext(ctx, "npm", "pkg", "set", packageSpecifier)
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error executing npm command %s: %w, output: %s", cmd.String(), err, out)
}
// Local SDKs have a postinstall script that needs to run to compile the SDK from TypeScript. Starting with
// npm 11.16.0, npm warns about packages whose install scripts are not covered by the `allowScripts` field in
// package.json, and npm 12 will skip those scripts unless they are allowlisted. Add the package to
// `allowScripts`, keyed by its `file:` dependency spec, so its install scripts keep running.
// https://docs.npmjs.com/cli/configuring-npm/package-json#allowscripts
cmd = exec.CommandContext(ctx, "npm", "pkg", "get", "allowScripts")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error running %s: %w, output: %s", cmd.String(), err, out)
}
out = bytes.TrimSpace(out)
allowScripts := map[string]bool{}
if len(out) > 0 && string(out) != "undefined" {
if err := json.Unmarshal(out, &allowScripts); err != nil {
allowScripts = map[string]bool{}
}
}
allowScripts["file:"+path] = true
jsonData, err := json.Marshal(allowScripts)
if err != nil {
return fmt.Errorf("error marshaling allowScripts to JSON: %w", err)
}
cmd = exec.CommandContext(ctx, "npm", "pkg", "set", "--json", "allowScripts="+string(jsonData))
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("error running %s: %w, output: %s", cmd.String(), err, out)
}View on GitHub (pinned to 793f7b2e16)
Solutions
- Upgrade npm to a version supporting `npm pkg get` (npm 7.24+)
- Validate package.json parses (e.g. `npm pkg get name`) in the target dir
- Inspect the wrapped output for npm's error and fix package.json
- Ensure Link is called on a directory containing package.json
Example fix
// before
mgr.Link(ctx, dir, pkg, path) // fails on old npm
// after
if err := exec.Command("npm", "pkg", "get", "name").Run(); err != nil {
return errors.New("npm is too old or package.json is invalid; upgrade npm")
}
mgr.Link(ctx, dir, pkg, path) Defensive patterns
Strategy: try-catch
Validate before calling
cmd := exec.Command("npm", "pkg", "get", "name")
cmd.Dir = dir
if err := cmd.Run(); err != nil {
return errors.New("npm pkg unsupported or package.json invalid; upgrade npm")
} Try / catch
if err := mgr.Link(ctx, dir, pkg, path); err != nil {
if strings.Contains(err.Error(), "unknown command") { /* upgrade npm */ }
return err
} Prevention
- Require npm >= 7.24 for `npm pkg` support
- Validate package.json parses before Link
- Run Link only at package roots
When it happens
Trigger: Calling npmManager.Link when `npm pkg get allowScripts` exits non-zero — e.g. corrupt package.json, npm version too old to support `pkg get`, or the working directory is not a package root.
Common situations: Old npm (< 8.x era without `pkg` subcommand support), malformed JSON in package.json, or running Link in a directory where package.json was deleted or is unreadable.
Related errors
- error executing npm command %s: %w, output: %s
- could not publish policies because of error running npm pack
- it looks like the policy pack's dependencies are not install
- it looks like the policy pack's dependencies are not install
- string(ee.Stderr)
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/c37cf46622467177.
Report an issue: GitHub.