0

I am working on two project, one which uses node 16 and one which uses node 18. I created a script in one of the projects to switch to 18 before running next dev.

Note: Nvm works in my terminal. I use zsh and installed nvm using homebrew.

The scriptlooks like this:


# Change to correct node version
source $(brew --prefix nvm)/nvm.sh
nvm use 18

# Wait for the database to start
sleep 5

# Start dev with sudo 
sudo yarn next dev

However when I run the script with yarn I get: nvm is not compatible with the "PREFIX" environment variable: currently set to "/opt/homebrew" Run `unset PREFIX` to unset it.

I have uninstalled node using brew, it does not help.

hagenek
  • 108
  • 1
  • 6

2 Answers2

0

Try installing nvm using the following script instead of using homebrew:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

And then close and reopen your terminal.

If the problem still persists, you could refer to this answer here:

https://stackoverflow.com/a/71282947/13007176

Ghouse Mohamed
  • 387
  • 4
  • 10
0

The below steps has worked for me in the ubuntu server where we use different node versions in server and in client folder. Install nvm in your system. Write shell script in the following format.

echo "Removing build files..";
rm -rf server/public/build
echo "Generating New Build....";
source $NVM_DIR/nvm.sh;
cd client
nvm use 14.16.1;
echo "Building Application";
npm install --legacy-peer-deps;
npm run build
echo "Building App Ends";
cd ..
nvm use 16.13.0;
npm install --legacy-peer-deps
Sunilkumar A
  • 111
  • 1
  • 3