Making node / npm / gulp / elixir work for Laravel using Homestead on Vagrant with Virtualbox on Windows

Wow what a title. More of a note to myself this one.

Problem: npm install or variants thereof cause errors, mainly related to long filenames when run inside a homestead virtualbox virtual machine on Windows.

A simple fix is to create a symbolic link inside the vm for the node_modules path so that it doesn't reside inside the folder being shared with the Windows file-system.

Modify the Vagrantfile or the scripts/homestead.rb file if using homestead to include the following as part of the config:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

Then you'll need to run the Git Bash shell as admin, otherwise it won't let you create the symbolic links. The important part here is actually that winnfsd.exe starts as admin so you could change the compatibility in the properties to start as admin.

Start vagrant with a "vagrant up"

Once you've done "vagrant ssh", create a node_modules directory in your home directory, or somewhere similar and add a symbolic link to it within your Laravel project:

mkdir ~/node_modules
ln -sf ~/node_modules /home/vagrant/projectname

Then you can use

sudo npm install —no-bin-link

to install the node modules with. You might have to "sudo" depending on your configuration and whether you have further issues.

Comments

Popular posts from this blog

Enabling SNMP on an ASUS RT-N66U

Making Microsoft Dataverse OData queries using Postman

Debugging multiple PHP projects with VS Code and Laragon