Exception: ViteRuby::MissingEntrypointError

Inherits:
Error
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vite_ruby/missing_entrypoint_error.rb

Overview

Internal: Raised when an entry is not found in the build manifest.

NOTE: The complexity here is justified by the improved usability of providing a more specific error message depending on the situation.

Constant Summary collapse

FAILED_BUILD_CAUSES =
"- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.\n"
DEFAULT_CAUSES =
"- The file path is incorrect.\n- The file is not in the entrypoints directory.\n- Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.\n"
NO_AUTO_BUILD_CAUSES =
"- You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.\n- \"autoBuild\" is set to `false` in your config/vite.json for this environment.\n"

Instance Method Summary collapse

Methods inherited from Error

#message

Constructor Details

#initialize(info) ⇒ MissingEntrypointError



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 11

def initialize(info)
  @info = info
  super <<~MSG
    Vite Ruby can't find #{ file_name } in #{ config.manifest_path.relative_path_from(config.root) } or #{ config.assets_manifest_path.relative_path_from(config.root) }.

    Possible causes:
    #{ possible_causes(last_build) }
    :troubleshooting:
    #{ "\nContent in your manifests:\n#{ JSON.pretty_generate(manifest) }\n" if last_build.success }
    #{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" unless last_build.success.nil? }
  MSG
end

Instance Method Details

#possible_causes(last_build) ⇒ Object



24
25
26
27
28
29
# File 'lib/vite_ruby/missing_entrypoint_error.rb', line 24

def possible_causes(last_build)
  return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
  return DEFAULT_CAUSES if config.auto_build

  DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
end