Brand new Rails 7.0 App - "The asset "application.js" is not present in the asset pipeline."

Created a new app with

rails new my_new_app -d postgresql -c sass

Added the sass script to package.json, generated a controller and a view, created the database and ran

yarn build:css --watch & rails s (SASS was not getting compiled without the first part)

At this point, I get

Sprockets::Rails::Helper::AssetNotFound in Home#index
The asset "application.js" is not present in the asset pipeline.

on the

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

What am I missing?

3 Likes

Just run into the same problem, Not sure if its the right approach or not, but what i did to make it work was to move the javascript folder to the assets folder, then in "assets/config/manifest.js " file added this:

//= link_directory /…/javascript .js

And it worked.

1 Like

Thanks. This helped with problem in Rails 6. Gave the clue I needed. Different path

1 Like

Hey thanks for sharing this post i was having some issues is your issue solved because i am not getting mine answer.

I had the same problem but with bootstrap and I tried your solution but I got this :

Its 2 dots before /javascript 2 dots mean folder that is one level higher than the current folder. If you are using VScode you can copy relative path by just right clicking the file whose path you want.

like this

//= link_tree ../images
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link frontend.js
//= link frontend.css
//= link admin.css
//= link admin.js
//= link dashboard/application.css
//= link dashboard/application.js

thank you Abdullah . it worked like charm

I’m sorry folks but probably your issue is caused by your OS, where esbuild Could not resolve “app/javascript/.” when your app was building:

So, you have to navigate to root folder of your app, and run manually this instruction, but specifying the application.js like this: ./app/javascript/application.js Do not move the folder, it will allow you to work with your css, but will ignore the javascripts.

also you can modify “package.json” like this

"scripts": {
    "build": "esbuild app/javascript/application.js --bundle --sourcemap --outdir=app/assets/builds",

so then you can re- run this command

yarn run build
1 Like

I’ve the same problem when i tring to start my project with: rails new project_name --css=bootstrap

I tried to reinstall ruby 3, rails 7, node, npm and npx. It didn’t solve. I’m going to try the answers below. I hope i handle it.

I think the problem is that you used npm instead of yarn. This means that 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.

I have been experiencing this issue with Rails 7.0.4 on macOS Ventura 13.0.1.

When I create a new Rails project that needs assets to be compiled, I get an error that The asset "application.js" is not present in the asset pipeline. I am using ./bin/dev to run the app. Using rails server yields the same behaviour.

For some strange reason, however, if I create and run the project from /tmp, it works.

I’d be grateful for any thoughts on how to fix this.

I tried your approach and it worked fine. But after several attempts on trying to customize Bootstrap components I can’t even point to the right stylesheet, my app now points everything the build folder. Do you know if this could be related to your solution?

The yarn run build worked for me. Thanks :pray:

1 Like

On Rails 7.0.4.3, this issue appears to be resolved for me.