{"record":{"id":"64b471cc0e145e9f","repo":"pulumi/pulumi","slug":"npm-pack-w","errorCode":null,"errorMessage":"npm pack: %w","messagePattern":"npm pack: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/nodejs/cmd/pulumi-language-nodejs/main.go","lineNumber":2099,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"copy package.json: %w\", err)\n\t\t}\n\t}\n\n\terr = writeString(\"$ npm pack\\n\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"write to output: %w\", err)\n\t}\n\tvar stdoutBuffer bytes.Buffer\n\tnpmPackCmd := exec.Command(npm,\n\t\t\"pack\",\n\t\tfilepath.Join(req.PackageDirectory, \"bin\"),\n\t\t\"--pack-destination\", req.DestinationDirectory)\n\tnpmPackCmd.Stdout = &stdoutBuffer\n\tnpmPackCmd.Stderr = struct{ io.Writer }{os.Stderr}\n\terr = npmPackCmd.Run()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"npm pack: %w\", err)\n\t}\n\n\tartifactName := strings.TrimSpace(stdoutBuffer.String())\n\n\treturn &pulumirpc.PackResponse{\n\t\tArtifactPath: filepath.Join(req.DestinationDirectory, artifactName),\n\t}, nil\n}\n\n// Nodejs sometimes sets stdout/stderr to non-blocking mode. When a nodejs subprocess is directly\n// handed the go process's stdout/stderr file descriptors, nodejs's non-blocking configuration goes\n// unnoticed by go, and a write from go can result in an error `write /dev/stdout: resource\n// temporarily unavailable`.\n//\n// The solution to this is to not provide nodejs with the go process's stdout/stderr file\n// descriptors, and instead proxy the writes through something else.\n// In https://github.com/pulumi/pulumi/pull/16504 we used Cmd.StdoutPipe/StderrPipe for this.\n// However this introduced a potential bug, as it is not safe to use these specific pipes along","sourceCodeStart":2081,"sourceCodeEnd":2117,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/nodejs/cmd/pulumi-language-nodejs/main.go#L2081-L2117","documentation":"This wraps a failure of the `npm pack <pkgdir> --pack-destination <dest>` command run by the language host when packing a NodeJS SDK. npm pack returns non-zero when the tarball cannot be produced (invalid package.json, lifecycle script failure, bad destination). The host then fails the Pack RPC with this error.","triggerScenarios":"Running Pack on a NodeJS package where `npm pack bin/ --pack-destination <dir>` exits non-zero: malformed or incomplete bin/package.json, npm lifecycle scripts (prepack/prepare) failing, missing files field collisions, unwritable DestinationDirectory, or npm not on PATH/npm registry issues triggering scripts.","commonSituations":"package.json missing required fields (name/version) in bin/; prepack script error; destination directory doesn't exist or is read-only; npm cache permission problems in CI; Node/npm version mismatch breaking the build scripts invoked by pack.","solutions":["Run `npm pack bin/ --pack-destination <dir>` manually in the package directory to see the real npm error.","Validate bin/package.json has valid name, version, and main/files entries.","Fix failing lifecycle scripts (prepack/prepare) or run them directly to see their failure.","Ensure DestinationDirectory exists and is writable; create it before packing.","Update npm/Node to supported versions and clear a corrupted npm cache (`npm cache verify`)."],"exampleFix":"// before: destination never created\nos.MkdirTemp(\"\", \"pulumipack\")\n// after: ensure destination exists before Pack\nos.MkdirAll(destDir, 0o755)","handlingStrategy":"validation","validationCode":"const pkg = JSON.parse(fs.readFileSync('bin/package.json', 'utf8'));\nif (!pkg.name || !pkg.version) throw new Error('bin/package.json needs name and version before npm pack');\nif (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });","typeGuard":null,"tryCatchPattern":"try { await pack(); } catch (err) { if (/npm pack/.test(String(err))) { console.error('Run `npm pack bin/` manually for the underlying npm error'); } throw err; }","preventionTips":["Validate bin/package.json contents before packing","Pre-create and permission the destination directory","Pin supported npm/Node versions in CI","Test lifecycle scripts (prepack) independently"],"tags":["nodejs","npm","pack","build"],"backgroundTag":"npm-pack-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}