To avoid any confusion regarding packages (which I've experienced myself), the best solution is to remove the node_modules
folder and then run npm i
again. Make sure that the list of dependencies in your package.json
file (including dev-dependencies and regular ones) matches the output of the command: npm ls --depth="0"
.
It's important that on both your PC and laptop, the result of running npm ls --depth="0"
matches the combined list of all dependencies listed in your package.json
. If they don't match, it could imply that npm has taken matters into its own hands 😁.
Some readers on SO may have down-voted your question assuming you didn't grasp the concept of dependencies having their own dependencies, hence the creation of additional folders.
I sincerely hope this isn't the case and that you won't be deterred by any negativity encountered on SO.
Another potential explanation for your situation could be if you forgot to include --save
when installing dependencies. This would result in the dependencies being saved in the node_modules
folder without being added to your package.json
, potentially leading to unnecessary installations.
By deleting the node_modules
folder and reinstalling, only the dependencies specified in the package.json
will be installed, ensuring a clean slate. This is why removing the node_modules
folder first is recommended. Automated npm publishing tools like my favorite np often perform a similar wipe and reinstall process before publishing to avoid any lingering issues in the node_modules
directory.
For more information on the importance of using --save
, I recommend checking out this insightful answer.
In response to previous suggestions, Jonathan mentioned using npm ls
, but I personally find it cumbersome for anything beyond simple libraries—too much scrolling. It's better to stick with npm ls --depth="0"
to focus solely on the top level of your dependencies.