Skip to content

Commit bdf15f2

Browse files
author
drmyersii
committed
This is a majorly important update.
It may not seem like it when checking out the code changes, but this update houses a huge fix for Windows based hosts. It is pretty well known that Windows paths cannot exceed ~260 characters, and this offers a huge problem for Node developers because of how npm handles nested modules. I have spent approximately 15 hours today (that is not an exaggeration), but I have finally built a solution to this problem. After many, many hours of searching, I finally came across some npm/node/vagrant issues that talk about a particular error involving Windows hosts for vagrant machines that house Node code. It took a bit of time just to narrow down that the error I was receiving was caused by this problem, but I finally did. The official NPM, Node, and Vagrant issue threads did not have any viable solutions for fixing this problem in an automated sense, so I spent the rest of my day (now ending at about 4:00 AM), and I built a solution in Vagrant that overcomes this issue. Feel free to check out this code. I'm sorry if my commit message is hard to follow, but I am tired. Good luck, and happy coding!
1 parent d812297 commit bdf15f2

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Vagrantfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# -*- mode: ruby; -*-
77

88
VAGRANTFILE_API_VERSION = "2"
9+
MAX_MEMORY = 1024
910

1011
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1112

@@ -16,11 +17,16 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1617
config.vm.network :forwarded_port, guest: 1337, host: 1337
1718

1819
# set up synced folder
19-
config.vm.synced_folder "./www", "/home/vagrant/www"
20+
#config.vm.synced_folder "./www", "/home/vagrant/www"
2021

21-
# if you are using VirtualBox, uncomment the line below to allow symlinks in the shared "www" folder
22-
#config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/home/vagrant/www", "1"]
22+
# settings for VirtualBox provider
23+
config.vm.provider "virtualbox" do |v|
24+
v.memory = MAX_MEMORY
25+
v.customize ["sharedfolder", "add", :id, "--name", "www", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/www").gsub("/","\\"))]
26+
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/home/vagrant/www", "1"]
27+
end
2328

24-
# call provisioner shell script
29+
# call provisioner shell scripts
30+
config.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` www /home/vagrant/www", run: "always"
2531
config.vm.provision :shell, path: "./provisioner.sh"
2632
end

provisioner.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ printf "Updating Box..."
66
# make sure the box is fully up to date
77
apt-get update
88

9-
# uncomment the line below to allow the system to upgrade
10-
#apt-get upgrade -y && apt-get dist-upgrade -y
9+
# comment out the line below to disallow the system to upgrade
10+
apt-get upgrade -y && apt-get dist-upgrade -y
1111

1212
printf "Adding MongoDB packages to apt..."
1313
# import the public key used by apt
@@ -21,7 +21,13 @@ apt-get update
2121

2222
printf "Installing a few necessary packages..."
2323
# install required packages
24-
apt-get install -y git npm mongodb-org redis-server
24+
apt-get install -y git nodejs nodejs-legacy npm mongodb-org redis-server
25+
26+
# make sure npm is up to date
27+
npm install -g npm
28+
29+
# remove old hash for npm so bash will find the new version
30+
hash -d npm
2531

2632
# backup mongodb-org config file
2733
cp /etc/mongod.conf /etc/mongod.conf.backup
@@ -75,5 +81,6 @@ cp /home/vagrant/.bashrc /home/vagrant/.bashrc.backup
7581
# if you don't want npm overridden, comment out the line below
7682
echo "alias npm='npm --no-bin-links'" >> /home/vagrant/.bashrc
7783

84+
printf "Making sure ownership rights are correct in vagrant user directory..."
7885
# make sure everything in the vagrant directory is owned by vagrant
7986
chown -R vagrant:vagrant /home/vagrant --quiet

0 commit comments

Comments
 (0)