how to switch node version
What is the type of issue?
Documentation is missing
What is the issue?
How can the node version that codex uses be changed?
It uses Node v18 by default. Prompting Codex to use nvm to switch the node version doesnt work. Here is a response that Codex gave
✓ Completed
└ ⌨️ echo "Checking for nvm..."; command -v nvm ||
echo "nvm not found"; echo "PATH=$PATH"; echo "Node
version:"; node -v
codex
I checked: this sandbox doesn’t have nvm available,
and Node is fixed at v18.16.0 for this session.
- nvm: not found
- PATH: shows host paths, but no nvm loader present
here
- node -v: v18.16.0
In another session on your machine you can absolutely
use nvm to switch to Node 22. In this Codex CLI
sandbox, the runtime is tied to the host image and
can’t be changed from inside the session. If you
want me to keep making progress here despite Node 18,
I can:
- Add a tiny vitest setup file to polyfill CustomEvent
so tests run under Node 18.
- Or flip specific tests to jsdom environment.
Where did you find it?
No response
In this session, I would like you to use Node 20 instead of the default 22. Can you switch the version using nvm via zsh? Then, use the switched node version for the following operations. Also, ensure each command runs with nvm use 20 in-session.
A prompt like this can work for your use case, but it's inefficient. So, I'd recommend simply running nvm use or having .nvmrc before starting a codex session.
Okay, so codex runs my shell correct?
If so, I need to figure out why it picks up v18 while my default is v22. The sandboxing stuff confused me. Codex said changing the node version is not possible because codex runs in a sandbox container which defaults to v18.
I'll try to fix the issue on my end tmr and report back
The bug seems to emerge because the default shell on mac os is zsh but codex runs in bash. The outcome are different environments.
Prob a good idea to use the default shell on the machine for codex?
nvm is just a bulky bash script which needs to be loaded for each shell session. So if you bootstrap nvm in zshrc file it might not be available because afaik codex executes commands in non-interactive mode.
Having same issue
Same here - using nvm to manage node, but sandbox is stuck on 18
Same here, i use node v22, but sandbox is on 18
Codex CLI in my case was using the Node.js binary from /usr/local/bin/node. The workaround is to upgrade that global Node.js installation.
- Navigate to this page: https://nodejs.org/en/download
- Choose macOS and click "macOS Installer (.pkg)" at the bottom
- The installer installs the updated Node.js to
/usr/local/bin/nodeand Codex picks it up
It doesn't solve the fact that Codex should probably use nvm out of the box.
I had the same issue and solved. The reason is I had multiple node, and my zsh shell uses the homebrew one, but the sandbox uses the /usr/local/bin/node one.
Just tell codex to run the following commands, then you know the problem:
which -a node
node -v
node -p "process.execPath"
For me, since I use the homebrew one, so my solution is simply deleting the lower version sudo rm -f /usr/local/bin/node.
same issue..
same here
I had the same issue and solved. The reason is I had multiple node, and my zsh shell uses the homebrew one, but the sandbox uses the
/usr/local/bin/nodeone.Just tell codex to run the following commands, then you know the problem:
which -a node node -v node -p "process.execPath"For me, since I use the homebrew one, so my solution is simply deleting the lower version
sudo rm -f /usr/local/bin/node.
This was the one thing that worked for me