Recently I needed to upgrade my Node version to >18 which let me update Vite >5. I encountered a big problem with Node soon. I have a project that is using Node 16 with vue-cli-server which means the project will not work if I update node forced to Node >18.
Yes, I know plenty of Node version management tools like n, and nvm, but all of them are not what I wanted. They both need to switch the Node version globally which means I can't run more than one project with a different Node version at the same time.
I am thinking、thinking…, Finally, I got an approach that can solve the problem elegantly. Just need to replace the shebang line which is at the top of the files in the node_modules/.bin
Before:
#!/usr/bin/env node
After:
#! /usr/local/n/versions/node/16.4.0/bin/node
The after is where the special Node is.I changed it on vue-cli-service in my older project, and it's working perfectly.
If you don't want to change this manually when the binary file is recovered by something like reinstall, just write a script to do this work.
Enjoying the dangerous but elegant approach.