Last modified: Jun 30, 2025 By Alexander Williams
Fix Error: Cannot find module 'socket.io-client'
If you see the error Cannot find module 'socket.io-client', don't worry. This is a common issue in Node.js. It means the module is missing or not installed correctly. Here's how to fix it.
What Causes This Error?
The error occurs when Node.js cannot locate the socket.io-client
module. This happens if the module is not installed, the installation failed, or the path is incorrect.
Similar errors like Cannot find module 'socket.io' or Cannot find module 'typescript' follow the same logic.
Solution 1: Install socket.io-client
The simplest fix is to install the module. Run this command in your project directory:
npm install socket.io-client
If you use Yarn, run:
yarn add socket.io-client
Solution 2: Check node_modules
If the module is installed but the error persists, check the node_modules
folder. Ensure socket.io-client
exists there.
If it's missing, delete node_modules
and package-lock.json
, then reinstall:
rm -rf node_modules package-lock.json
npm install
Solution 3: Verify Import Path
Ensure your import statement is correct. Use:
const io = require('socket.io-client'); // Correct
A typo like socket-io-client
or socket.io.client
will cause the error.
Solution 4: Global vs Local Installation
If you installed socket.io-client
globally, your project may not detect it. Always install locally:
npm install socket.io-client --save
Solution 5: Update Node.js and npm
Outdated tools can cause module issues. Update Node.js and npm:
npm install -g npm@latest
Then, reinstall the module.
Solution 6: Clear npm Cache
A corrupted cache can cause installation failures. Clear it with:
npm cache clean --force
Then, reinstall socket.io-client
.
Solution 7: Check package.json
Ensure socket.io-client
is listed in package.json
under dependencies
or devDependencies
.
If not, add it manually and run npm install
.
Solution 8: Rebuild Dependencies
For native modules, rebuild dependencies with:
npm rebuild
Solution 9: Check File Permissions
Ensure you have read/write permissions in the project folder. On Linux/macOS, run:
sudo chown -R $(whoami) node_modules
Solution 10: Use a Different Version
If the latest version causes issues, try an older one:
npm install socket.io-client@2.4.0
Conclusion
The Cannot find module 'socket.io-client' error is easy to fix. Most times, reinstalling the module works. If not, try clearing the cache or updating Node.js.
For similar issues like Cannot find module 'webpack', the solutions are often the same.
Now you can connect your app with Socket.IO without errors!