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