{"record":{"id":"c37cf46622467177","repo":"pulumi/pulumi","slug":"error-running-s-w-output-s-c37cf4","errorCode":null,"errorMessage":"error running %s: %w, output: %s","messagePattern":"error running (.+?): %w, output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/nodejs/npm/npm.go","lineNumber":111,"sourceCode":"\nfunc (node *npmManager) Link(ctx context.Context, dir, packageName, path string) error {\n\tpackageSpecifier := getLinkPackageProperty(packageName, path)\n\tcmd := exec.CommandContext(ctx, \"npm\", \"pkg\", \"set\", packageSpecifier)\n\tcmd.Dir = dir\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"error executing npm command %s: %w, output: %s\", cmd.String(), err, out)\n\t}\n\n\t// Local SDKs have a postinstall script that needs to run to compile the SDK from TypeScript. Starting with\n\t// npm 11.16.0, npm warns about packages whose install scripts are not covered by the `allowScripts` field in\n\t// package.json, and npm 12 will skip those scripts unless they are allowlisted. Add the package to\n\t// `allowScripts`, keyed by its `file:` dependency spec, so its install scripts keep running.\n\t// https://docs.npmjs.com/cli/configuring-npm/package-json#allowscripts\n\tcmd = exec.CommandContext(ctx, \"npm\", \"pkg\", \"get\", \"allowScripts\")\n\tcmd.Dir = dir\n\tout, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error running %s: %w, output: %s\", cmd.String(), err, out)\n\t}\n\tout = bytes.TrimSpace(out)\n\tallowScripts := map[string]bool{}\n\tif len(out) > 0 && string(out) != \"undefined\" {\n\t\tif err := json.Unmarshal(out, &allowScripts); err != nil {\n\t\t\tallowScripts = map[string]bool{}\n\t\t}\n\t}\n\tallowScripts[\"file:\"+path] = true\n\tjsonData, err := json.Marshal(allowScripts)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error marshaling allowScripts to JSON: %w\", err)\n\t}\n\tcmd = exec.CommandContext(ctx, \"npm\", \"pkg\", \"set\", \"--json\", \"allowScripts=\"+string(jsonData))\n\tcmd.Dir = dir\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"error running %s: %w, output: %s\", cmd.String(), err, out)\n\t}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/nodejs/npm/npm.go#L93-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nmgr.Link(ctx, dir, pkg, path) // fails on old npm\n// after\nif err := exec.Command(\"npm\", \"pkg\", \"get\", \"name\").Run(); err != nil {\n    return errors.New(\"npm is too old or package.json is invalid; upgrade npm\")\n}\nmgr.Link(ctx, dir, pkg, path)","handlingStrategy":"try-catch","validationCode":"cmd := exec.Command(\"npm\", \"pkg\", \"get\", \"name\")\ncmd.Dir = dir\nif err := cmd.Run(); err != nil {\n    return errors.New(\"npm pkg unsupported or package.json invalid; upgrade npm\")\n}","typeGuard":null,"tryCatchPattern":"if err := mgr.Link(ctx, dir, pkg, path); err != nil {\n    if strings.Contains(err.Error(), \"unknown command\") { /* upgrade npm */ }\n    return err\n}","preventionTips":["Require npm >= 7.24 for `npm pkg` support","Validate package.json parses before Link","Run Link only at package roots"],"tags":["npm","nodejs","allowscripts","exec"],"backgroundTag":"npm-command-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}