Problems with the npm firewall file system

I met a common mistake with Vagrant and npm machines, where the file system suddenly becomes read-only. In all cases, a synchronized directory containing the git repository was involved.

Here is the setup setting that I came across. Both files are in the root directory of the node-oriented git repository, for example this one .

Vagrantfile

 # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Use host SSH keys config.ssh.forward_agent = true # Get current directory name (presumably, repo dirname) repo_dirname = File.basename(Dir.getwd) # Set US locale ENV['LC_ALL']="en_US.UTF-8" # Ensures virtualbox can create symlinks in shared folders config.vm.provider "virtualbox" do |vb| vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"] end # Forward usual dev port through to host machine config.vm.network :forwarded_port, guest: 3000, host: 3000 # Also forward production port just in case config.vm.network :forwarded_port, guest: 80, host: 8080 # Forward a folder for the repo so that code can be worked on from outside the # VM as usual config.vm.synced_folder ".", "/home/ubuntu/#{repo_dirname}", create: true config.vm.define "#{repo_dirname}-vm" do |repo_vm| repo_vm.vm.box = "ubuntu/xenial64" repo_vm.vm.host_name = "#{repo_dirname}-vm" repo_vm.vm.provision :shell do |sh| sh.path = "vagrant_provision.sh" sh.privileged = false sh.env = { REPO_DIR: repo_dirname } end end end 

vagrant_provision.sh

 #!/usr/bin/env bash function set_locale() { sudo locale-gen en.US } function get_builds() { sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y curl build-essential } function get_n_installer() { if [ -f n-install ] then echo "n installer already exists. Not downloading." return 0 else echo "n installer not found. Downloading..." wget -L https://git.io/n-install fi } function install_n() { if [ -d "n" ] then echo "n install directory already exists. Not installing." return 0 else echo "n install directory not found. Installing..." yes | bash n-install fi } function add_github_keys() { # Adds the github server key to known hosts ssh-keyscan github.com >> ~/.ssh/known_hosts && return 0 || return 1 } function add_n_to_path() { # Added by n-install, but ignored by vagrant export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin" } function get_repo() { if [ -d "$2" ] then echo "Destination directory $2 already exists. Deleting contents..." rm -rfv ./$2 fi echo "Cloning $1 into $2..." git clone $1 $2 } function install_npm_deps() { echo "Installing npm dependencies..." npm install } function rebuild_node_sass() { # Needed because of https://github.com/sass/node-sass/issues/1579 npm rebuild node-sass } # . ~/.bashrc && set_locale && add_github_keys && get_builds && get_n_installer && install_n && add_n_to_path && cd $REPO_DIR && install_npm_deps && rebuild_node_sass && echo "Provisioned user is: $USER" && echo "Frontend provisioned. To run, type 'vagrant ssh'." 

The main step that seems to be causing the problem is to run npm install unprivileged provisioning tool. Sometimes an unpacking error occurs, but in other cases npm fails with ENOENT errors.

When you log in with vagrant ssh to complete the job, read-only file system errors appear. Despite this, there is enough space in the system (for example, 7 out of 8 GB left).

Read-only file system errors also appear when the webpack server is running under the same circumstances.

There are questions and tickets floating around this quote of similar errors, but I have not seen any research into what underlies the mechanism. What a deal?

+5
source share
2 answers

I am having similar problems with Vagrant 1.8.7 and Virtualbox 5.1.10. I was able to fix the file system with a readiness for the problem by reducing the number of processor cores to 1:

 config.vm.provider "virtualbox" do |v| v.cpus = 1 end 

Construction problems are still happening for me (npm modules not found, ENOENT, ELIFECYCLE, ...), but at least. Unfortunately, I could not find the root cause of these errors.

In my installation, npm is not written to the shared directory. If the recording location is a shared folder, you can try a different synchronization mechanism that bypasses some of the limitations of implementing a virtual virtual folder.

+1
source

I managed to fix this problem by linking node_modules to the external / roaming shared folder ie / home / vagrant / node_modules:

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

The disadvantage of this is that you will no longer be able to install npm outside the vagabonds, only from the inside (unless you use mkdir / vagrant on your main machine).

+1
source

Source: https://habr.com/ru/post/1262656/


All Articles