{"record":{"id":"9ee4b5cba348e586","repo":"pulumi/pulumi","slug":"find-npm-w","errorCode":null,"errorMessage":"find npm: %w","messagePattern":"find npm: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/nodejs/cmd/pulumi-language-nodejs/main.go","lineNumber":1983,"sourceCode":"\nfunc readPackageJSON(packageJSONPath string) (map[string]any, error) {\n\tpackageJSONData, err := os.ReadFile(packageJSONPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read package.json: %w\", err)\n\t}\n\tvar packageJSON map[string]any\n\terr = json.Unmarshal(packageJSONData, &packageJSON)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal package.json: %w\", err)\n\t}\n\treturn packageJSON, nil\n}\n\nfunc (host *nodeLanguageHost) Pack(ctx context.Context, req *pulumirpc.PackRequest) (*pulumirpc.PackResponse, error) {\n\t// Verify npm exists and is set up: npm, user login\n\tnpm, err := executable.FindExecutable(\"npm\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"find npm: %w\", err)\n\t}\n\n\t// Annoyingly the engine will call Pack for the core SDK which is not setup in at all the same way as the\n\t// generated sdks, so we have to detect that and do a big branch to pack it totally differently.\n\tpackageJSON, err := readPackageJSON(filepath.Join(req.PackageDirectory, \"package.json\"))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// TODO: We're just going to write to stderr for now, but we should probably have a way to return this\n\t// directly to the engine hosting us. That's a bit awkward because we need the subprocesses to write to\n\t// this as well, and the host side of this pipe might be a tty and if it is we want the subprocesses to\n\t// think they're connected to a tty as well. We've solved this problem before in two slightly different\n\t// ways for InstallDependencies and RunPlugin, it would be good to come up with a clean way to do this for\n\t// all these cases.\n\twriteString := func(s string) error {\n\t\t_, err = os.Stderr.Write([]byte(s))\n\t\treturn err","sourceCodeStart":1965,"sourceCodeEnd":2001,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/nodejs/cmd/pulumi-language-nodejs/main.go#L1965-L2001","documentation":"Pack resolves npm once at the start of the language host's Pack method via executable.FindExecutable(\"npm\") (sdk/nodejs/cmd/pulumi-language-nodejs/main.go:1983). If no npm binary can be located on PATH (or via nodeenv paths), the error is wrapped as \"find npm: %w\" and packing aborts before reading package.json.","triggerScenarios":"Calling Pack (e.g. 'pulumi package pack-sdk' or 'pulumi plugin install' flows that build a Node package) on a machine where the 'npm' executable is not on PATH and not in the nodeenv/npm shims the host checks.","commonSituations":"Node.js not installed in the environment running the pulumi CLI; npm not installed despite node being present (e.g. custom node builds); PATH stripped of nvm/volta/n dirs in CI or non-interactive shells; mise/asdf shim directories missing.","solutions":["Install Node.js (which bundles npm) in the environment running pulumi, e.g. via nvm, volta, mise, or the OS package manager","Ensure the directory containing npm is on PATH for the shell/process invoking pulumi: 'which npm' must succeed","In CI, use a setup-node/setup step before running pulumi commands","If using nvm, confirm the default alias exists ('nvm alias default') so non-interactive shells resolve node/npm","As a workaround, symlink npm into a directory already on PATH"],"exampleFix":"// before\n$ pulumi package pack-sdk nodejs ./provider\nerror: find npm: exec: \"npm\": executable file not found in $PATH\n// after\n$ export PATH=\"$HOME/.nvm/versions/node/v20.11.0/bin:$PATH\"\n$ which npm\n$ pulumi package pack-sdk nodejs ./provider","handlingStrategy":"validation","validationCode":"if ! command -v npm >/dev/null 2>&1; then\n  echo \"npm not found on PATH\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":"try {\n  child_process.execSync('npm --version');\n} catch (err) {\n  console.error('npm is not available on PATH; install Node.js first');\n  process.exit(1);\n}","preventionTips":["Install Node.js via a version manager and ensure the shell init (nvm/volta/mise) runs in non-interactive shells too","Verify 'which npm' before running pulumi pack commands in CI","Add a setup-node step before any pulumi invocation","Keep PATH consistent between your shell and the process invoking pulumi"],"tags":["nodejs","npm","path","environment"],"backgroundTag":"missing-executable-on-path","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}