Skip to content

Commit 258fa4c

Browse files
committed
fix: ensure node is in PATH when executing npm
- npm's shebang (#!/usr/bin/env node) requires node in PATH - When executing npm, add node's directory to PATH in subprocess environment - Find node in same directory as npm or via nvm path detection - This fixes 'No such file or directory' error when npm tries to execute Fixes issue where npm version check fails because node is not in Jupyter kernel's PATH, even though both are installed via nvm.
1 parent b680114 commit 258fa4c

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

notebooks/setup/complete_setup_guide.ipynb

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,48 @@
119119
" try:\n",
120120
" # For npm, ensure we have proper environment (especially for nvm)\n",
121121
" env = os.environ.copy()\n",
122-
" # If npm is in nvm path, ensure NODE_PATH is set\n",
123-
" if 'nvm' in command_path and command == 'npm':\n",
124-
" nvm_dir = os.path.dirname(os.path.dirname(command_path))\n",
125-
" if 'NODE_PATH' not in env:\n",
126-
" env['NODE_PATH'] = nvm_dir\n",
122+
" # If npm is in nvm path, ensure node is in PATH (npm's shebang needs it)\n",
123+
" if command == 'npm':\n",
124+
" # Find where node is located\n",
125+
" node_path = shutil.which('node')\n",
126+
" if not node_path:\n",
127+
" # Try to find node in the same directory as npm\n",
128+
" node_dir = os.path.dirname(command_path)\n",
129+
" node_candidate = os.path.join(node_dir, 'node')\n",
130+
" if os.path.exists(node_candidate):\n",
131+
" node_path = node_candidate\n",
132+
" else:\n",
133+
" # Try nvm paths\n",
134+
" nvm_paths = [\n",
135+
" os.path.expanduser(\"~/.nvm/versions/node\"),\n",
136+
" os.path.expanduser(\"~/.config/nvm/versions/node\"),\n",
137+
" ]\n",
138+
" for nvm_base in nvm_paths:\n",
139+
" if os.path.exists(nvm_base):\n",
140+
" try:\n",
141+
" versions = sorted([d for d in os.listdir(nvm_base) if os.path.isdir(os.path.join(nvm_base, d))])\n",
142+
" if versions:\n",
143+
" latest = versions[-1]\n",
144+
" node_candidate = os.path.join(nvm_base, latest, \"bin\", \"node\")\n",
145+
" if os.path.exists(node_candidate):\n",
146+
" node_path = node_candidate\n",
147+
" break\n",
148+
" except:\n",
149+
" pass\n",
150+
" \n",
151+
" # If we found node, add its directory to PATH\n",
152+
" if node_path:\n",
153+
" node_dir = os.path.dirname(node_path)\n",
154+
" current_path = env.get('PATH', '')\n",
155+
" # Add node directory to PATH if not already there\n",
156+
" if node_dir not in current_path:\n",
157+
" env['PATH'] = f\"{node_dir}:{current_path}\"\n",
158+
" \n",
159+
" # Also set NODE_PATH for npm modules\n",
160+
" if 'nvm' in command_path:\n",
161+
" nvm_dir = os.path.dirname(os.path.dirname(command_path))\n",
162+
" if 'NODE_PATH' not in env:\n",
163+
" env['NODE_PATH'] = nvm_dir\n",
127164
" \n",
128165
" result = subprocess.run(\n",
129166
" [command_path, version_flag],\n",

0 commit comments

Comments
 (0)