Skip to content

rails new doesn't install required npm dependencies #54992

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

Closed
j127 opened this issue Apr 29, 2025 · 6 comments
Closed

rails new doesn't install required npm dependencies #54992

j127 opened this issue Apr 29, 2025 · 6 comments

Comments

@j127
Copy link

j127 commented Apr 29, 2025

Steps to reproduce

Create a new Rails project like this:

rails _8.0.2_ new my_website --js=esbuild --css=tailwind --database=postgresql

Run:

bin/setup

Expected behavior

The command should succeed and the server should be running, because bin/setup runs bin/dev.

Actual behavior

The command fails because there aren't any npm dependencies installed.

$ bin/setup

== Installing dependencies ==
The Gemfile's dependencies are satisfied
yarn install v1.22.22
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Saved lockfile.
✨  Done in 0.03s.

== Preparing database ==
Created database 'my_website_development'
Created database 'my_website_test'

== Removing old logs and tempfiles ==

== Starting development server ==
12:23:09 web.1  | started with pid 11853
12:23:09 js.1   | started with pid 11854
12:23:09 css.1  | started with pid 11855
12:23:09 js.1   | yarn run v1.22.22
12:23:09 css.1  | yarn run v1.22.22
12:23:09 css.1  | $ npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify --watch
12:23:09 js.1   | $ esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets --watch
12:23:09 js.1   | /bin/sh: esbuild: command not found
12:23:09 js.1   | error Command failed with exit code 127.
12:23:09 js.1   | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:23:10 js.1   | exited with code 127
12:23:10 system | sending SIGTERM to all processes
12:23:11 css.1  | exited with code 1
12:23:11 web.1  | terminated by SIGTERM

Here's the package.json -- shouldn't tailwind and esbuild be there (edit: and hotwire dependencies)?

{
  "name": "app",
  "private": true,
  "scripts": {
    "build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
    "build:css": "npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
  }
}

Edit: here are some more logs -- it's running yarn add but the dependencies aren't found in package.json:

...

  Install esbuild
         run    yarn add --dev esbuild from "."
  Add build script
         run    npm pkg set scripts.build="esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets" from "."
         run    yarn build from "."
         run  bundle install --quiet
       rails  turbo:install stimulus:install
       apply  /Users/username/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/turbo-rails-2.0.13/lib/install/turbo_with_node.rb
  Import Turbo
      append    app/javascript/application.js
  Install Turbo
         run    yarn add @hotwired/turbo-rails from "."
         run  bundle install --quiet
       apply  /Users/username/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/stimulus-rails-1.3.4/lib/install/stimulus_with_node.rb
  Create controllers directory
      create    app/javascript/controllers
      create    app/javascript/controllers/index.js
      create    app/javascript/controllers/application.js
      create    app/javascript/controllers/hello_controller.js
  Import Stimulus controllers
      append    app/javascript/application.js
  Install Stimulus
         run    yarn add @hotwired/stimulus from "."
         run  bundle install --quiet
       rails  css:install:tailwind
       apply  /Users/username/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/cssbundling-rails-1.4.3/lib/install/tailwind/install.rb
       apply    /Users/username/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/cssbundling-rails-1.4.3/lib/install/install.rb
    Build into app/assets/builds
       exist      app/assets/builds
   identical      app/assets/builds/.keep
   unchanged      .gitignore
   unchanged      .gitignore
    Remove app/assets/stylesheets/application.css so build output can take over
      remove      app/assets/stylesheets/application.css
      append      Procfile.dev
    Add bin/dev to start foreman
   identical      bin/dev
  Install Tailwind
      create    app/assets/stylesheets/application.tailwind.css
         run    yarn add tailwindcss@latest @tailwindcss/cli@latest from "."
  Add build:css script
  Add build:css script
         run    npm pkg set scripts.build:css="npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify" from "."
         run    yarn build:css from "."
         run  bundle install --quiet
         run  bundle binstubs kamal
         run  bundle exec kamal init
Created configuration file in config/deploy.yml
Created .kamal/secrets file
Created sample hooks in .kamal/hooks
       force  .kamal/secrets
       force  config/deploy.yml
       rails  solid_cache:install solid_queue:install solid_cable:install
      create  config/cache.yml
      create  db/cache_schema.rb
        gsub  config/environments/production.rb
      create  config/queue.yml
      create  config/recurring.yml
      create  db/queue_schema.rb
      create  bin/jobs
        gsub  config/environments/production.rb
      create  db/cable_schema.rb
       force  config/cable.yml

System configuration

Rails version: 8.0.2

Ruby version: ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]

(M1 MacBook)

@j127
Copy link
Author

j127 commented Apr 29, 2025

I figured out the problem. I had upgraded Node to the latest minor version with nvm earlier, which meant yarn wasn't installed any more.

It might be a good idea to have rails new --css=tailwind --js=eslint fail if yarn isn't installed so there isn't a silent error.

@MatheusRich
Copy link
Contributor

@j127 maybe this is an improvement you can make at jsbundling-rails? Or maybe even moving this issue there?

@j127
Copy link
Author

j127 commented Apr 30, 2025

Does rails new use jsbundling-rails? Sorry, I don't know how it works under the hood yet. I'll take a closer look.

@MatheusRich
Copy link
Contributor

@j127 if you use --js=esbuild it will. By default, it uses importmaps

@j127
Copy link
Author

j127 commented Apr 30, 2025

Thanks, I'll search around in the code and see if I can figure out how it works.

@j127
Copy link
Author

j127 commented May 1, 2025

I moved it here for now, so I'll close this issue.

@j127 j127 closed this as completed May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants