Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite dev exits without any error message, explanation, or traceback #22

Closed
mattlong opened this issue Mar 2, 2021 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@mattlong
Copy link

mattlong commented Mar 2, 2021

Description 📖

I was attempting to try out vite in a small rails application by following the Installation/Getting Started sections of the README. bundle exec vite install worked without issue. Without editing the generated config files at all, I ran bundle exec vite dev which quickly exited with exit code 1. The only output shown was the general vite command usage as shown below. The same behavior occurs with bin/vite dev and npx vite dev. While the failure itself is clearly problematic, the more immediate issue is that isn't any error logging nor any (documented) command line args to enable more verbosity or change the logging level.

I am willing to dive into the vite JS modules to do some debugging and hopefully figure out what is going wrong, but that is difficult to do since vite_ruby passes all commands through npx rather than just adding vite to my package.json (which would be my preference, to be honest) and installing them in my local node_modules.

It's a very bare bones repository thus far; essentially a fresh vanilla rails 6 install with a few common gems and node modules.

Reproduction 🐞

Not available

Vite Ruby Info

Run bin/rake vite:info and provide the output:

Is bin/vite present?: true
vite_ruby: 1.0.4
vite_rails: 2.0.2
rails: 6.0.3.4
node: v14.15.0
npm: 6.14.8
yarn: 1.22.10
ruby: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]

vite-plugin-ruby:
myrepo@0.1.0 /Users/myname/projects/myrepo
`-- (empty)

Logs 📜

If not providing a reproduction:

Output

Run DEBUG=vite-plugin-ruby:* bin/vite dev or DEBUG=vite-plugin-ruby:* bin/vite build and provide the output:

$ DEBUG=vite-plugin-ruby:* bin/vite dev
Commands:
  vite build          # Bundle all entrypoints using Vite.
  vite dev            # Start the Vite development server.
  vite install        # Performs the initial configuration setup to get started with Vite Ruby.
  vite version        # Print version
$ echo $?
1

The same output is received with DEBUG=* bin/vite dev

$ DEBUG=vite-plugin-ruby:* bin/vite build
I, [2021-03-02T11:37:14.241059 #63530]  INFO -- : Building with Vite ⚡️
^C#<Thread:0x00007f94681eb758 /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:287 run> terminated with exception (report_on_exception is true):
#<Thread:0x00007f94681eb230 /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:288 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
	1: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:287:in `block (2 levels) in capture3'
/Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:287:in `read': IOError
Traceback (most recent call last):
	1: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:288:in `block (2 levels) in capture3'
/Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:288:in `read': IOError
Traceback (most recent call last):
	21: from bin/vite:29:in `<main>'
	20: from bin/vite:29:in `load'
	19: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/exe/vite:10:in `<top (required)>'
	18: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/dry-cli-0.6.0/lib/dry/cli.rb:67:in `call'
	17: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/dry-cli-0.6.0/lib/dry/cli.rb:114:in `perform_registry'
	16: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/cli/build.rb:16:in `call'
	15: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:12:in `build_from_task'
	14: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:141:in `with_node_env'
	13: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:13:in `block in build_from_task'
	12: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:149:in `ensure_log_goes_to_stdout'
	11: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:14:in `block (2 levels) in build_from_task'
	10: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/commands.rb:21:in `build'
	 9: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/builder.rb:15:in `build'
	 8: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/builder.rb:71:in `build_with_vite'
	 7: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/forwardable.rb:235:in `run'
	 6: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/runner.rb:11:in `run'
	 5: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/vite_ruby-1.0.4/lib/vite_ruby/runner.rb:30:in `execute_command'
	 4: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:281:in `capture3'
	 3: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:101:in `popen3'
	 2: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:219:in `popen_run'
	 1: from /Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:298:in `block in capture3'
/Users/myname/.rbenv/versions/2.7.1/lib/ruby/2.7.0/open3.rb:298:in `value': Interrupt

I cancelled the build command after it hung for 12 minutes.

Screenshots 📷

@mattlong mattlong added the bug: pending triage Something doesn't seem to be working, but hasn't been verified label Mar 2, 2021
@ElMassimo
Copy link
Owner

ElMassimo commented Mar 2, 2021

Hi there! Thanks for providing the logs.

It's unlikely that npx vite returns the same error as the other commands, as it doesn't run any Ruby code, where the CLI is defined.

Looking at the output of the info command, it would seem that vite-plugin-ruby and vite were not installed, likely due to a bug in the logic in this library's installation command which I'm planning to investigate tomorrow.

I have documented this common problem, and I'm planning to add a verification check to prevent silent failures when these packages are missing.

Please add vite-plugin-ruby and vite as development dependencies, install them (yarn, npm, pnpm, whatever you are using), and try again.

About the last comment, using the bin/vite executable ensures any config overrides added in Ruby are passed to Vite, such as Rails environment, but in most setups running npx vite is the same so feel free to add a script in your package.json if you prefer that, it will still read the config/vite.json configuration.

@mattlong
Copy link
Author

mattlong commented Mar 2, 2021

After a bit more looking at the source, it seems the root problem is that npx @antfu/ni -D #{ deps } command is not actually adding the two deps as is being expected; hence my comments above them not showing up in my package.json after vite install. I'm not familiar with antfu/ni and not really sure why the command wouldn't be working as expected and apparently failing silently.

Manually running yarn add -D vite@^2.0.3 vite-plugin-ruby@^1.0.13 clears up the issue and bin/vite dev no longer exits immediately 🎊

To your comment about verification, I believe running npx vite without vite being installed locally would still work, no? It seems like a safer verification might be just making sure vite is listed as a dev dependency in package.json.

@ElMassimo
Copy link
Owner

Agreed, for verification I'm thinking of checking both the plugin and vite are installed.

I'll leave this open as a reminder to fix the installation (it seems the command is succeeding so the yarn fallback is not used, but it's not actually installing the packages), and to add the verification before the dev and build commands.

Thanks for the report!

@ElMassimo ElMassimo added bug Something isn't working and removed bug: pending triage Something doesn't seem to be working, but hasn't been verified labels Mar 2, 2021
@mattlong
Copy link
Author

mattlong commented Mar 2, 2021

Sure thing, thanks for working on this! I've gotten tired of all of webpack's complexity and am hoping this can be viable alternative to webpacker!

@ElMassimo
Copy link
Owner

ElMassimo commented Mar 2, 2021

It has been for me! Vite's defaults are great, and at the same time it's very easy to configure (TypeScript-enabled config file), and to extend with plugins.

Webpack is great too, but it requires a significant amount of configuration and specific knowledge about its internals.

Because of that, webpacker attempts to provide an "out of the box" experience, which then makes it really hard to eject from if you want to instead use something like vue-cli.

That's why this library is intentionally narrow in scope: simplify Vite.js integration with Ruby, and get out of the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants