Getting `error Command "vite" not found.` on Github actions
jasonfb opened this issue · comments
Describe the bug
I realize this may be related to Github actions, but I am posting here for reference.
although my Selenium spec passes locally, on GH Actions I am getting error Command "vite" not found
my .github/worksflows/test_suite.yml
file is as follows:
# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.
#
# This workflow will install a prebuilt Ruby version, install dependencies, and
# run tests and linters.
name: "Your CI"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11-alpine
ports:
- "5432:5432"
env:
POSTGRES_DB: rails_test
POSTGRES_USER: rails
POSTGRES_PASSWORD: password
chrome:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444
env:
RAILS_ENV: test
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 18
- name: Set up database schema
run: bin/rails db:schema:load
- name: Run tests
run: bin/rake
I think this should be right, but on Github actions, but my test is failing with:
Possible causes:
- The last build failed. Try running `bin/vite build --clear --mode=test` manually and check for errors.
Errors:
error Command "vite" not found.
Visit the Troubleshooting guide for more information:
https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting
>
F
Failures:
1) homepage can load
Failure/Error: <%= vite_typescript_tag 'application' %>
ActionView::Template::Error:
Vite Ruby can't find entrypoints/application.ts in public/vite-test/manifest.json or public/vite-test/manifest-assets.json.
Possible causes:
- The last build failed. Try running `bin/vite build --clear --mode=test` manually and check for errors.
Errors:
error Command "vite" not found.
the app boots and the test passes fine locally.
is there something special I have to do on Github Actions to make Vite work?
Reproduction
https://github.com/jasonfb/VRGitHubActionDemo
Steps to reproduce
echo "please give your new Vite Rails app a TitleCase name:" && read APP_NAME && rails new $APP_NAME --skip-javascript --database=postgresql && cd $APP_NAME && git checkout -b main && CURRENT_NODE=$(nvm current) && printf $CURRENT_NODE >> .node-version && printf "Node + Ruby versions are in \`.node-version\` and \`.ruby-version\`, respectively.\n\n# Setup\n\n\`bin/setup\`\n\n# Start Rails\n\n\`bin/vite dev\` + \`bin/rails s\` in two separate windows\nor run \`bin/dev\` in single window and access site at http://127.0.0.1:5100\n\n# Run Specs\n\nrun with \`bin/rake\`" > README.md && git add . && git commit -m "initial commit with $(rails -v), Node $CURRENT_NODE, Ruby $(more ./.ruby-version)" && ./bin/setup && sed -i '' -e 's/ruby-//g' .ruby-version && RUBY_STRING="ruby \"$(more ./.ruby-version)\"" && sed -i '' -e "s/$RUBY_STRING/ruby File.read('.ruby-version').strip/g" Gemfile && git add . && git commit -m "fixes .ruby-version file and sets Gemfile to use .ruby-version file" && npm init -y && git add . && git commit -m "initalizes npm" && bundle add vite_rails && bundle install && git add . && git commit -m "adds vite-rails gem" && bundle exec vite install && git add . && git commit -m "vite rails default setup" && yarn add react react-dom && git add . && git commit -m "yarn add react react-dom" && rails generate controller Welcome && sed -i '' -e 's/class WelcomeController < ApplicationController/class WelcomeController < ApplicationController\n def index\n\n end/g' app/controllers/welcome_controller.rb &&
printf "<div id=\"${APP_NAME}App\"></div>" > app/views/welcome/index.html.erb &&
sed -i '' -e 's/# root "articles#index"//g' config/routes.rb &&
sed -i '' -e 's/Rails.application.routes.draw do/Rails.application.routes.draw do\n root to: "welcome#index"/g' config/routes.rb && git add . && git commit -m "generates Welcome controller" && printf "import App from '~/components/App'\nimport React from 'react'\nimport { createRoot } from 'react-dom/client'\nconst root = createRoot(document.getElementById('${APP_NAME}App'))\nroot.render(React.createElement(App))" >> app/frontend/entrypoints/application.js && mkdir app/frontend/components && printf "import React from 'react';\nexport default function App () {\n return (<h1>Hello Vite Rails</h1>)\n}" >> app/frontend/components/App.jsx && git add . && git commit -m "basic shell for React app" && printf '#!/usr/bin/env sh\n\nif ! gem list foreman -i --silent; then\n echo "Installing foreman..."\n gem install foreman\nfi\n\nexec foreman start -f Procfile.dev "$@"' > bin/dev && chmod 0755 bin/dev && git add . && git commit -m "adding bin/dev option to start both vite + rails in one terminal window using Foreman"
bundle add rspec-rails rspec-wait factory_bot_rails ffaker vcr simplecov dotenv-rails --group "development, test" && bundle add simplecov-rcov launchy --group "test" &&
rails generate rspec:install && mkdir spec/features &&
git add . && git commit -m "adds rspec, factory boy, ffaker, vcr, simplecov, and launchy" && printf "\n.env\n.env.local\n.env.*.local\n\ncoverage/" >> .gitignore && printf "" >> .env.local && git add . && git commit -m "adds .env, etc and coverage/ to .gitignore file" && sed -i '' -e 's/RSpec.configure do |config|/RSpec.configure do |config|\n config.include FactoryBot::Syntax::Methods/g' spec/rails_helper.rb && sed -i '' -e "s/RSpec.configure do |config|/require 'simplecov'\nrequire 'simplecov-rcov'\nclass SimpleCov::Formatter::MergedFormatter\n def format(result)\n SimpleCov::Formatter::HTMLFormatter.new.format(result)\n SimpleCov::Formatter::RcovFormatter.new.format(result)\n end\nend\nSimpleCov.formatter = SimpleCov::Formatter::MergedFormatter\nSimpleCov.start 'rails' do\n add_filter \"\/vendor\"\nend\n\nRSpec.configure do |config|/g" spec/rails_helper.rb &&
git add . && git commit -m "adding factorybot and simplecov to Rspec config"
printf "require 'rails_helper'\n\ndescribe 'homepage' do\n it 'can load' do\n visit '/'\n expect(page).to have_content('Hello Vite Rails')\n end\nend" >> spec/features/homepage_spec.rb && printf "Capybara.register_driver :selenium do |app|\n options = Selenium::WebDriver::Chrome::Options.new(\n # It's the headlese arg that make Chrome headless\n # + you also need the disable-gpu arg due to a bug\n args: ['headless', 'disable-gpu window-size=1366,1200'],\n )\n\n Capybara::Selenium::Driver.new(\n app,\n browser: :chrome,\n options: options\n )\nend\n\nCapybara.default_driver = :selenium" >> spec/rails_helper.rb && git add . && git commit -m "basic capybara example"
run specs locally with bin/rake
, specs should pass
• run bundle lock --add-platform x86_64-linux
and commit changes
• run bin/rails db:migrate
and commit schema file
add the file .github/workflows/test_suite.yml
(see above), push to Github.
On GIthub actions, it fails with:
2023-07-13 23:29:09 +0000 Rack app ("GET /" - (127.0.0.1)): #<ActionView::Template::Error: Vite Ruby can't find entrypoints/application.js in public/vite-test/manifest.json or public/vite-test/manifest-assets.json.
Possible causes:
- The last build failed. Try running `bin/vite build --clear --mode=test` manually and check for errors.
Errors:
error Command "vite" not found.
System Info
Github Actions CI runner
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
This is solved.
In my github actions setup, I simply had failed to include a step for
- name: npm install
run: npm install
Hey, I'm running the same issue, I already tried npm install
but didn't work out.
Okay, GA got fixed using npm install
but you need to have a package-lock.json
instead of yarn.lock
Here is the PR if that helps...