stream浪汉文件系统与npm的问题

我一直遇到Vagrant机器和npm频繁的错误,在那里文件系统突然变成只读。 在所有情况下,涉及一个包含git回购的同步目录。

这是一个configuration设置,我已经能够遇到问题。 这两个文件都位于面向节点的git存储库的根目录下,就像这个一样。

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's 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'." 

似乎导致问题的主要步骤是非特权供应商执行npm install 。 有时会发生归档解包错误 ,但是有时候,npm会失败并显示ENOENT错误。

在login时使用vagrant ssh来完成作业,出现只读文件系统错误。 尽pipe如此,系统上还是有很多空间的(比如剩下8GB中的7个)。

webpack服务器在相同情况下运行时,只读文件系统错误也会出现。

有些问题和票据引用了类似的错误,但我还没有看到底层机制是什么。 这是怎么回事?

我一直在遇到与Vagrant 1.8.7和Virtualbox 5.1.10类似的问题。 我能够通过将CPU核心数量减less到1来修复文件系统的只读问题。

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

对我来说,构build问题仍然存在(npm模块没有find,ENOENT,ELIFECYCLE,…),但速度较慢。 不幸的是,我一直无法find这些错误的根本原因。

在我的设置npm不写入共享目录。 如果写入位置是共享文件夹,则可以尝试使用其他同步机制来解决virtualbox共享文件夹实施的一些限制。

我设法通过symlinking / vagrant共享文件夹/ home / vagrant / node_modules之外的node_modules解决此问题:

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

这样做的缺点是你不能在外面安装npm,只能从内部安装(除非你的主机上有mkdir / vagrant)。