node_modules in vagrant environment

Submitted by oioioooi on 05/03/2022 - 19:02

Running npm install in a vagrant made environment is most likely to cause weirdo errors, spoiled or missing packages.

The issue is that node_modules directory is located in same directory as the project source files and during npm install the contents of this folder are attempted to be synced between virtual and host machines, therefore causing errors.

The solution is to use a bind mount on node_modules folder.

Assuming that you use a bootstrap shell script and your source files are mapped to /www directory, the following snipped solves the problem.

sudo -u vagrant mkdir /home/vagrant/node_modules
sudo -u vagrant mkdir /www/node_modules
mount --bind /home/vagrant/node_modules /www/node_modules

 

Tags