I’m having trouble with my project setup. My application was built to work with socket.io version 6.x and everything runs perfectly with that version. However, I need to deploy my app to a different server environment now. When I run the standard npm install command for socket.io, it automatically grabs the newest version which is 7.x. This creates compatibility issues with my existing codebase since there are breaking changes between these major versions. I need to force npm to download and install the older 6.x release instead of the current one. What’s the proper syntax or method to specify an exact version number during npm installation?
Another approach that saved me from similar headaches is using npm shrinkwrap or package-lock.json to lock down your entire dependency tree. I had a project where socket.io 6.x was working fine, but even after installing the correct version, some of its dependencies were pulling in newer incompatible packages. What worked was first clearing node_modules completely with rm -rf node_modules, then doing npm install [email protected] followed by npm shrinkwrap. This creates a shrinkwrap file that locks every single dependency version. When deploying to your new server, the shrinkwrap ensures identical versions get installed every time. I also keep the specific version documented in my deployment notes because inevitably someone will need to troubleshoot this months later when the project gets handed off.
u just gotta slap the version number after the @ when installin. like npm install [email protected] or whichever 6.x u need. also, try npm install socket.io@^6.0.0 for latest 6.x without heading to 7.x.
The version pinning approach mentioned above works well, but I’d recommend taking it a step further for production stability. After installing the specific version with npm install [email protected] (or whatever 6.x version you need), check your package.json to ensure it shows the exact version without any caret or tilde prefixes. Sometimes npm still adds those range specifiers which could cause issues later. You can also use npm install [email protected] --save-exact to force exact version matching. I learned this the hard way when a minor version update broke my WebSocket connections in production. Also worth running npm ls socket.io afterward to verify the correct version is actually installed, since dependency conflicts can sometimes override your specified version.