Erdem TOPAL
Erdem TOPAL

Reputation: 31

The asset “application.js” is not present in the asset pipeline in rails 7

I started new project with rails 7 and ruby 3 : rails new erdemsproject --css=bootstrap $rails g controller page index (after that in routes: root “home#index” )

$rails s

And I’m giving a basic error in localhost’s red page: The asset “application.js” is not present in the asset pipeline. on the:

<%= javascript_include_tag “application”, “data-turbo-track”: “reload”, defer: true %>

What is the mistake? I installed yarn, npm, npx and ruby again and again. But didn't solve.

Upvotes: 3

Views: 7006

Answers (4)

Erica
Erica

Reputation: 221

I had same issue for my Rails 7 project

Solution:

  1. Add webpacker gem: gem 'webpacker'
  2. Install webpacker from terminal: rake webpacker:install
  3. Run command yarn build

Hope this helps.

Upvotes: 1

Chrispaix
Chrispaix

Reputation: 71

in your app/views/layouts/applications.html.erb instead of :

  <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>

do :

<%= javascript_include_tag "/assets/application.js", "data-turbo-track": "reload", defer: true %>

Upvotes: 7

NYAME
NYAME

Reputation: 61

If you used the command

rails new myapp -j webpack

to generate your app, and tried to use npm instead of yarn to install dependencies. webpack cannot compile the code generated. By default, the files generated, in Procfile.dev, you have:

js: yarn build --watch

either install yarn or if u want to use npm change this to:

js: npm run build -- --watch

then run

npm install -D webpack-cli the error should clear.

Upvotes: 0

For a rails 7 app initialize with css flag you need to run your project with:

./bin/dev

Because you need to build your css and js with cssbundling-rails and jsbundling-rails.

Upvotes: 4

Related Questions