Ruby on Rails project not compilation assets without show errors, Heroku - ruby-on-rails

Preparing app for Rails asset pipeline
Running: rake assets:precompile
yarn install v1.22.17
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning " > react-dom#17.0.2" has incorrect peer dependency "react#17.0.2".
[5/5] Building fresh packages...
Done in 27.74s.
Compiling...
Compilation failed:
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app.
! Push failed
On local machine RAILS_ENV=production rails assets:precompile compile without errors.

Related

Rails deploy fails, as SSHKit command failed

The latest in rails 6 deployment problems when compiling javascript assets. The error points to
1: from /Users/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in
'rescue in block (2 levels) in execute': Exception while executing as deploy#16.17.18.2: rake exit status: 1
(SSHKit::Runner::ExecuteError)
[...]
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: yarn install v1.22.17
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 25.51s.
Compiling...
Compilation failed:
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy#16.17.18.2: rake exit status: 1
rake stdout: yarn install v1.22.17
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 25.51s.
Compiling...
Compilation failed:
rake stderr: Nothing written
I have no clue what is going on here. How should this be addressed?
If asset precompilation is working on the remote server directly then it’s time to look at what conditions SSHKit sets up when capistrano connects to the server:
Is there a timeout on the ssh connection?
What environment variables are set when you SSH directly vs in the SSHKit session?
There is a Capistrano —-trace option that can help you reveal more info.

error Command "webpack" not found - when deploying basic Rails app on Heroku

I am trying to follow this tutorial to deploy a basic "Hello, world!" app using Rails and Heroku.
I get to the git push heroku main command and hit the error message below when I run it.
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: yarn install v1.22.4
remote: [1/4] Resolving packages...
remote: error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
remote: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
remote: I, [2021-11-22T22:40:17.749803 #1743] INFO -- : Writing /tmp/build_c74ce4bc/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js
remote: I, [2021-11-22T22:40:17.750027 #1743] INFO -- : Writing /tmp/build_c74ce4bc/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js.gz
remote: I, [2021-11-22T22:40:17.750167 #1743] INFO -- : Writing /tmp/build_c74ce4bc/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css
remote: I, [2021-11-22T22:40:17.750260 #1743] INFO -- : Writing /tmp/build_c74ce4bc/public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz
remote: Compiling...
remote: Compilation failed:
remote: yarn run v1.22.4
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote:
remote:
remote: error Command "webpack" not found.
remote:
remote:
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
I meet all of the Heroku tutorial's pre-requisites and I am using specific versions of ruby and Rails to match the Learn enough rails tutorial
$ ruby -v
ruby 2.7.4p191
$ rails -v
Rails 6.1.4.1
$ gem -v
3.2.31
$ Bundler -v
Bundler version 2.2.31
I've tried using yarn to add webpack and webpack-cli packages to dependencies in package.json file. But that hasn't helped.
I'm quite new to programming so I might be missing something obvious. Does anyone have any pointers?
Thank you!
Update: Seemed the issue arose because I had a version of yarn in my home directory that was too recent. Resolved issue by installing same version of yarn that heroku tried to run at deployment (v1.22.4) and using this version to yarn install and update the yarn.lock file.

Heroku: Error - /bin/sh: 1: npm: not found when deploying to Heroku

I have a Rails 6 Application which I just built.
However, when I try deploying to Heroku from my command line using:
git push heroku master
I get the error below after some :
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.1: The platform "linux" is incompatible with this module.
info "fsevents#1.1.1" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
$ npm run build
/bin/sh: 1: npm: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
I have re-run the command several times, but I still get the same error.
I finally figured out the issue.
The issue was because I did not have a Nodejs Build pack to run the npm run build command for assets compilation.
Here's how I fixed it:
I added the Nodejs buildpack to the application with the buildpacks:add command:
heroku buildpacks:add --index 1 heroku/nodejs
This will insert the Node.js buildpack at the first position in the order of buildpack execution, and move the other buildpacks that are ahead of it down one position.
Note: The buildpack for the primary language of your app should be the last buildpack added. In this case Ruby is our primary language.
You can then view the buildpacks for your application:
heroku buildpacks
=== nameless-brushlands-4859 Buildpack
1. heroku/nodejs
2. heroku/ruby
Note: The last buildpack in the list will be used to determine the process types for the application.
You should always specify a Node.js version, npm version and yarn version that matches the runtime you’re developing and testing with. To find your version locally:
node --version
npm --version
yarn --version
Now, use the engines section of the package.json to specify the version of Node.js, npm version and yarn version to use on Heroku.
"version": "0.1.0",
"engines": {
"node": "12.x",
"npm": "6.x",
"yarn": "1.x"
},
Now you can deploy to Heroku and it will work fine:
git add .
git commit -m "add nodejs buildpack"
git push heroku master
That's all.
I hope this helps

Rails 6.0 w/Webpacker: Heroku Push Fail: error: RPC failed; curl 18 transfer closed with outstanding read data remaining

When pushing to Heroku, I'm encountering a timeout while compiling, as in the trace below:
...
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Installing yarn-v1.12.3
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: yarn install v1.12.3
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: info fsevents#1.2.9: The platform "linux" is incompatible with this module.
remote: info "fsevents#1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
remote: [3/4] Linking dependencies...
remote: warning "#rails/webpacker > pnp-webpack-plugin > ts-pnp#1.1.2" has unmet peer dependency "typescript#*".
remote: warning " > rails-erb-loader#5.5.2" has unmet peer dependency "webpack#^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
remote: warning " > webpack-dev-server#3.3.1" has unmet peer dependency "webpack#^4.0.0".
remote: warning "webpack-dev-server > webpack-dev-middleware#3.6.2" has unmet peer dependency "webpack#^4.0.0".
remote: [4/4] Building fresh packages...
remote: Done in 24.78s.
remote: Compiling…
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: el remoto se colgó de manera inesperada
fatal: el remoto se colgó de manera inesperada
I've tried several times with same result.
I haven't changed anything that to my mind mey be causing this issue.
The last commited changes were mainly in JS files, and as it hangs while compiling, I guess it has something to do with JS assets.
Thanks for any help you can give.
Well, after all I found the problem myself. It was an import of a file that had been removed. Webpacker wasn't throwing any errors, which had been hidding the issue.
Thanks!

webpacker won't compile when pushing to Heroku

I've recently tried integrating react into my preexisting rails app by using the webpacker gem. When I try to push to heroku, I see the an error message like
remote: [1/5] Validating package.json...
remote: [2/5] Resolving packages...
remote: [3/5] Fetching packages...
remote: [4/5] Linking dependencies...
remote: [5/5] Building fresh packages...
remote: success Saved lockfile.
remote: Done in 0.09s.
remote: Compiling…
remote: Compilation failed:
remote: error Command "webpack" not found.
remote:
remote: yarn run v1.12.3
remote: info Visit https://yarnpkg.com/en/docs/cli/run for
documentation about this command.
remote:
remote:
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to spitball-production.
remote:
To https://git.heroku.com/spitball-production.git
! [remote rejected] master -> master (pre-receive hook declined)
My package.json looks like
{
"name": "Spitball",
"private": true,
"dependencies": {
},
"engines": {
"yarn": ">=0.25.2"
}
}
I've tried the solutions involving adding buildpacks and installing yarn and webpacker and so far nothing has helped. I'm expecting everything to push through no problem as all I've done is add the webpacker gem.
Did you try running
$ rails assets:precompile
in your terminal prior to pushing to Github then Heroku?
You have to compile all of your assets files prior to being built by Heroku.

Resources