hashicorp/vagrant · error · Vagrant::Errors::PackageOutputExists

The specified file '%{filename}' to save the package as alre

Error message

The specified file '%{filename}' to save the package as already exists. Please remove this file or specify a different file name for outputting.

What it means

Package.validate! refuses to overwrite existing output: after expanding the --output path (default package.box in the cwd), if a regular file already exists there, PackageOutputExists is raised with its basename. This is a deliberate guard so repeated packaging runs don't silently clobber previous .box artifacts.

Source

Thrown at lib/vagrant/action/general/package.rb:45

        # Perform sanity validations that the provided output filepath is sane.
        # In particular, this function validates:
        #
        #   - The output path is a regular file (not a directory or symlink)
        #   - No file currently exists at the given path
        #   - A directory of package files was actually provided (internal)
        #
        # @param [String] output path to the output file
        # @param [String] directory path to a directory containing the files
        def self.validate!(output, directory)
          filename = File.basename(output.to_s)
          output   = fullpath(output)

          if File.directory?(output)
            raise Vagrant::Errors::PackageOutputDirectory
          end

          if File.exist?(output)
            raise Vagrant::Errors::PackageOutputExists, filename: filename
          end

          if !Vagrant::Util::Presence.present?(directory) || !File.directory?(directory)
            raise Vagrant::Errors::PackageRequiresDirectory
          end
        end

        # Calculate the full path of the given path, relative to the current
        # working directory (where the command was run).
        #
        # @param [String] output the relative path
        def self.fullpath(output)
          File.expand_path(output, Dir.pwd)
        end

        # The path to the final output file.
        # @return [String]
        attr_reader :fullpath

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Delete or move the existing file: `rm -f package.box` (or your --output path), then re-run `vagrant package`.
  2. Or write each run to a fresh name: `vagrant package --output "mybox-$(date +%Y%m%d-%H%M%S).box"`.
  3. In CI, add a cleanup step before the package step.

Example fix

# before
vagrant package --output myapp.box   # second run => PackageOutputExists

# after
rm -f myapp.box && vagrant package --output myapp.box
# or versioned outputs:
vagrant package --output "myapp-$(date +%Y%m%d-%H%M%S).box"
Defensive patterns

Strategy: validation

Validate before calling

# Shell: package only when the output path is clear
out="${PACKAGE_OUT:-package.box}"
if [ -e "$out" ] && [ ! -d "$out" ]; then rm -f "$out"; fi
vagrant package --output "$out"

Prevention

When it happens

Trigger: Running `vagrant package [--output X]` when X (or ./package.box) already exists as a file — running package twice, CI re-runs without workspace cleanup, or a stale artifact from an earlier attempt (lib/vagrant/action/general/package.rb:44-46).

Common situations: scripted packaging loops that use a fixed output name; CI pipelines re-running on the same workspace; iterating on a box locally and forgetting the previous file.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/80a3085c357606e3. Report an issue: GitHub.