Skip to content
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

Precompiling assets on Heroku fails with /bin/sh: 1: npm: not found #2254

Closed
trcarden opened this issue Aug 27, 2019 · 13 comments
Closed

Precompiling assets on Heroku fails with /bin/sh: 1: npm: not found #2254

trcarden opened this issue Aug 27, 2019 · 13 comments

Comments

@trcarden
Copy link
Contributor

Summary

When using the latest heroku ruby build pack (https://github.com/heroku/heroku-buildpack-ruby) and deploying a standard rails 5.2+ application the asset compilation yields a broken compilation every time.

Expected Behavior

When you deploy to heroku assets compile with the standard ruby buildpack

Actual behavior

webpacker or related system seems to call out to NPM incorrectly and assets are not able to be compiled.

Repo

Was able to repro by simply deploying a standard empty application with the 4.0.7 release and then tagging master in both package.json and Gemfile. The difference causes a failure.

Output

Failure Output

yarn install v1.16.0
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info No lockfile found.
       warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
       [1/5] Validating package.json...
       [2/5] Resolving packages...
       warning @webpack-contrib/defaults > mrm-core > [email protected]: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
       warning @webpack-contrib/defaults > mrm-core > comment-json > [email protected]: `json-parser` is deprecated. Please use `comment-json` instead
       warning [email protected]: This module is no longer maintained, try this instead:
         npm i nyc
       Visit https://istanbul.js.org/integrations for other alternatives.
       warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: use String.prototype.padStart()
       [3/5] Fetching packages...
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       [4/5] Linking dependencies...
       [5/5] 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.

Output on 4.0.7 tag

       yarn install v1.16.0
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info No lockfile found.
       warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
       [1/5] Validating package.json...
       [2/5] Resolving packages...
       warning @webpack-contrib/defaults > mrm-core > [email protected]: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
       warning @webpack-contrib/defaults > mrm-core > comment-json > [email protected]: `json-parser` is deprecated. Please use `comment-json` instead
       warning [email protected]: This module is no longer maintained, try this instead:
         npm i nyc
       Visit https://istanbul.js.org/integrations for other alternatives.
       warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: use String.prototype.padStart()
       [3/5] Fetching packages...
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       [4/5] Linking dependencies...
       [5/5] Building fresh packages...
       success Saved lockfile.
       info [email protected]: The platform "linux" is incompatible with this module.
       info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
       warning [email protected]: The engine "browser" appears to be invalid.
       [3/4] Linking dependencies...
       warning " > [email protected]" has unmet peer dependency "@babel/core@^7.0.0".
       [4/4] Building fresh packages...
       Done in 67.42s.
       Compiling…
       Compiled all packs in /tmp/build_f3df98f5306c014d494d7e85b0898b4f/public/packs
@jakeNiemiec
Copy link
Member

jakeNiemiec commented Aug 27, 2019

$ npm run build
       /bin/sh: 1: npm: not found

I think the problem is this line, what is in that script? Is npm installed on the remote?

@hiimtaylorjones
Copy link
Contributor

Hey there,

I would suggest one of two things here:

  • Specify an NPM or Yarn engine in your package.json
  • Add the Heroku NodeJS buildpack to your app. This will allow your dyno to have npm installed and properly build your app

@trcarden
Copy link
Contributor Author

trcarden commented Aug 29, 2019

Perhaps let me cross link this with another ticket so the maintainer on the heroku buildpack can get involved.

Here is the heroku ruby build pack which should work without having to install the nodejs buildpack (it has yarn and npm support for sprockets and other versions of rails.)

heroku/heroku-buildpack-ruby#912

My hunch was that the latest webpacker system started to rely on npm despite the rails default is still yarn. Given that it works with the webpacker stable branch and fails on master I thought one of you guys would know where that might be coming from. I did a little grepping but it doesn't look like there is a npm reference to build in webpacker.

I originally thought it might be something to do with the node upgrade b4057d7 and the way heroku's build pack detects what to do with a rails project.

If I have a bit more time in a week or so I will see if I can debug a bit more and help out

@hiimtaylorjones
Copy link
Contributor

Timothy,

Do you mind providing us with the package.json you're using here? I linked this earlier, but the Ruby buildpack detects whether to use npm or yard from the "engines" section of your package.json.

@adenta

This comment has been minimized.

@tmoney100

This comment has been minimized.

@szTheory
Copy link
Contributor

This error can occur if you update the webpacker gem without updating the corresponding NPM packages. Make sure to run all the commands from https://github.com/rails/webpacker#upgrading

bundle update webpacker
rails webpacker:binstubs
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest

@matthewgoodwin

This comment has been minimized.

@jakeNiemiec jakeNiemiec changed the title Precompiling assets on Heroku fails on master Precompiling assets on Heroku fails with /bin/sh: 1: npm: not found Jan 17, 2020
@jakeNiemiec
Copy link
Member

To everyone in this thread:

If your issue is not related to /bin/sh: 1: npm: not found, please create another issue with the details of your problem. In order to help debug, consider posting as much as you can of:

  • ./package.json
  • ./babel.config.js
  • ./config/webpack/environment.js
  • ./config/webpacker.yml
  • ./app/javascript/packs/application.js (or the file related to the error)
  • the full error message (even the parts you wouldn’t think of as relevant)

I am going to hide the errors that don't seem related to this issue. You may also find some heroku-specific solutions in: #395

@jakeNiemiec
Copy link
Member

info [email protected]: The platform "linux" is incompatible with this module.
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".

@matthewgoodwin You have several warnings, but this 👆 is probably the source of your problems. If you open a new issue, I can advise further.

@gathuku
Copy link

gathuku commented Jan 28, 2020

Am having this issue deploying rails 6 on heroku , Any solution?

Have tried defining engines in package.json but doest work

@ahowardm
Copy link

I was having the same issue with rails 6.0.2 and webpack and solved it adding two buildpacks to the heroku app (Settings > Buildpacks > Add buildpack):

  1. heroku/nodejs
  2. heroku/ruby

imagen

It is very important the order, at first I had ruby and then nodejs and it didn't work.

@gathuku
Copy link

gathuku commented Jan 29, 2020

@ahowardm Following your guide i was able to get it. But also had to disable rails default yarn install , since it was installing node packages and gems twice. see code

Rake::Task['yarn:install'].clear
namespace :yarn do
  desc "Disabling internal yarn install from Rails"
  task :install => [:environment] do
    puts "Disabling internal yarn install from Rails"
  end
end

Rake::Task['webpacker:yarn_install'].clear
namespace :webpacker do
  desc "Disabling internal yarn install from Rails"
  task :yarn_install => [:environment] do
    puts "Disabling internal yarn install from Rails"
  end
end

More https://dev.to/vvo/a-rails-6-setup-guide-for-2019-and-2020-hf5

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

9 participants