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

Command "webpack" not found. #522

Closed
johnbeynon opened this issue Jun 20, 2017 · 30 comments
Closed

Command "webpack" not found. #522

johnbeynon opened this issue Jun 20, 2017 · 30 comments

Comments

@johnbeynon
Copy link

I'm deploying an upgraded Rails 4.x -> 5.1 app to Heroku and am getting the error

Command "webpack" not found.

I've gone on to the dyno directly and attempted to run rake assets:precompile which fails with the message:

Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
[Webpacker] Compiling assets 🎉
[Webpacker] Compilation Failed
yarn run v0.22.0
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

error Command "webpack" not found.

This seems to be coming from

stdout_str, stderr_str, status = Open3.capture3(env, "./bin/webpack")

Am I correct in understanding that executing rake assets:precompile is all that needs to occur for a deployment? ie, that handles installing the yarn dependencies etc?

I found that if I do yarn install first and then assets:precompile it works - but I didn't think I had to do that.

~ $ rake webpacker:verify_install
Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
@ytbryan
Copy link
Contributor

ytbryan commented Jun 20, 2017

Please read #512

Do you think this fix your problem?

@johnbeynon
Copy link
Author

I don't think so.

It shouldn't be necessary to add the node buildpack, Node is already available in the Ruby buildpack.

Heroku invokes rake assets:precompile which I believe should be enhanced by webpacker to do the yarn install bit...but that doesn't happen.

@schneems
Copy link
Member

@ytbryan the buildpack maintainer here. You do not need to use the Node buildpack.

@ytbryan
Copy link
Contributor

ytbryan commented Jun 20, 2017

cc @gauravtiwari what do you think is the issue here?

@gauravtiwari
Copy link
Member

@johnbeynon Do you have yarn binstub in your bin folder?

@gauravtiwari
Copy link
Member

Seems like the task is invoked but there is no yarn binstub present since you were using Rails 4.

screen shot 2017-06-20 at 20 33 27

Please regenerate them - bundle install --binstubs

@gauravtiwari
Copy link
Member

@schneems Do you think it would be better and makes sense if Heroku takes cares of this? Rails with webpacker is essentially a Ruby + Node app and therefore it should have same deployment behaviour as Ruby and Node buildpack combined.

@schneems
Copy link
Member

I'm trying to take care of it. We installed Ruby and we installed yarn. I don't know what is failing or why? Do you know where in the code that error message comes from Command "webpack" not found.?

I have access to that app (John actually works for Heroku, this is an internal app that he's working for).

I tried generating that binstub, but that file is not generated:

$ git status
On branch schneems/rails51
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   bin/rails
	modified:   bin/rake
	modified:   bin/spring

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	bin/_guard-core
	bin/bourbon
	bin/bundler
	bin/coderay
	bin/dotenv
	bin/erubis
	bin/guard
	bin/heroics-generate
	bin/heroku-api
	bin/htmldiff
	bin/ldiff
	bin/listen
	bin/mongrel_rpm
	bin/newrelic
	bin/newrelic_cmd
	bin/nokogiri
	bin/nrdebug
	bin/pry
	bin/puma
	bin/pumactl
	bin/rackup
	bin/rdoc
	bin/ri
	bin/rollbar-rails-runner
	bin/rspec
	bin/ruby-prof
	bin/ruby-prof-check-trace
	bin/sass
	bin/sass-convert
	bin/scss
	bin/sdoc
	bin/sdoc-merge
	bin/sprockets
	bin/thor
	bin/tilt

This is in:

    webpacker (2.0)

@gauravtiwari
Copy link
Member

@schneems From here - https://github.com/rails/webpacker/blob/master/lib/install/bin/webpack.tt#L23 So the compiler invokes the binstub which tries to run webpack executable using yarn

@gauravtiwari
Copy link
Member

Looks like it's only gets generated with rails new (5.1+) - https://github.com/rails/rails/blob/801b33a4812c937a7e726d4060e2e3e9361c56fa/railties/lib/rails/generators/rails/app/templates/bin/yarn

@schneems
Copy link
Member

Thanks! I manually created bin/yarn with these contents:

#!/usr/bin/env ruby
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
  begin
    exec "yarnpkg #{ARGV.join(" ")}"
  rescue Errno::ENOENT
    puts "Yarn executable was not detected in the system."
    puts "Download Yarn at https://yarnpkg.com/en/docs/install"
  end
end

Then made the file executable via chmod. After adding to git and deploying, it got rid of this specific error.

Weird that this was required as yarn is installed and on the system path.

Questions

  1. Is there a better way to generate that binstub for yarn?
  2. If this causes errors (running without a binstub) will future versions that do not use a binstub cause an error? Nix yarn binstub #367

@gauravtiwari
Copy link
Member

Ideally, I would suggest to include this behaviour as default like in Node buildpack.

#367 removed yarn binstub from webpacker in favour of using yarn executable directly on the system. The problem here is the app is generated/upgraded locally where a user either manually runs yarn install or webpacker:install which basically installs all dependencies but during deployment since webpacker doesn't ship with yarn executable anymore the command fails (unless on new Rails 5.1+)

Until we have a proper solution, perhaps we put back the yarn binstub that was removed in #367 so we don't break the current deployment workflow for users who are either on rails < 5.1 or transitioning to Rails 5.1.

What do you think?

@gauravtiwari
Copy link
Member

@schneems
Copy link
Member

I'm not sure. I don't totally know what everything here does.

What does the bin/yarn do? It looks like it just converts the yarn *args* call to yarnpkg *args*.

@gauravtiwari
Copy link
Member

gauravtiwari commented Jun 20, 2017

Yes, it's bit confusing actually - bin/yarn shouldn't be there and that's why i removed it in #367.

The idea was to simply use yarn executable directly, which is available by default - both locally and on Heroku.

You see here -

unless Rake::Task.task_defined?("yarn:install")
we are checking if there is an yarn:install task is present (from rails 5.1+) and if not we are enhancing it with webpacker yarn_install - https://github.com/rails/webpacker/blob/master/lib/tasks/webpacker/yarn_install.rake

Now if an app is just updated to Rails 5.1 and does't have bin/yarn file present that conditional block will pass because the rails 5.1 has this task already defined however the actual task will fail at runtime because there is no bin/yarn file.

@gauravtiwari
Copy link
Member

For anyone updating from Rails 4.x to 5.1.x to add yarn binstub -

bundle config --delete bin
# Will create yarn binstub
rails app:update:bin
git add bin

gauravtiwari pushed a commit that referenced this issue Jun 21, 2017
* webpack or webpack-dev-server not found

Add to troubleshooting of readme to prevent such issues #379 (comment), #506

* Update README.md

* Update README.md

* Include solution for error occurring in heroku

* Update README.md

Since it is known that node buildpacks is not necessary Read: #522 (comment)

* Update README.md

* Update README.md

Include instruction while upgrading from rails 4 to 5.

* Minor update

* Use ./bin/rails

* Add as comment
@gauravtiwari
Copy link
Member

@johnbeynon @schneems Is all okay now? I have documented this in README.

@johnbeynon
Copy link
Author

Totally happy. Closing.

@jnfeinstein
Copy link

Currently fighting this issue on Rails 4.2, Webpacker 2, Yarn 1.0.1. Is there a hotfix for this configuration? Will updating to Webpacker 3 fix the issue? Updating to Rails 5.1 is not currently an option.

@gauravtiwari
Copy link
Member

@jnfeinstein Just install webpacker, bundle exec rails webpacker:install. Also you would need to remove ./bin folder from .gitignore

@jnfeinstein
Copy link

@gauravtiwari thank you for the suggestions. It appears that adding the yarn binstub above fixed the issue.

moveson added a commit to SplitTime/OpenSplitTime that referenced this issue Oct 23, 2017
sensiblegame added a commit to sensiblegame/webpack that referenced this issue Oct 23, 2017
* webpack or webpack-dev-server not found

Add to troubleshooting of readme to prevent such issues rails/webpacker#379 (comment), rails/webpacker#506

* Update README.md

* Update README.md

* Include solution for error occurring in heroku

* Update README.md

Since it is known that node buildpacks is not necessary Read: rails/webpacker#522 (comment)

* Update README.md

* Update README.md

Include instruction while upgrading from rails 4 to 5.

* Minor update

* Use ./bin/rails

* Add as comment
@donnfelker
Copy link

Leaving this comment for folks who run across this in the future. My issue was that the version of node I had (8.0.0) was too low. I needed, IIRC, 8.9.0 or greater. I upgraded to 11.13.0 and re-ran the commands rails webpacker:install commands and all was golden.

@mtoygar
Copy link

mtoygar commented Jun 15, 2019

In my case rails webpacker:install was silently 'failing'. When I check node_modules/.bin folder there was no webpack file and this results in the Command "webpack" not found. error. (webpack source code reference)

After some investigation, I manually tried to add webpack using yarn add --dev webpack webpack-dev-serveryarn add webpack webpack-dev-server command and saw the below error(webpack module cant be installed because of some DNS related problem).

error An unexpected error occurred: "https://registry.npmjs.org/webpack: Hostname/IP does not match certificate's altnames: Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net".

After some research, the above problem is solved with the command below.

dig https://registry.npmjs.org/webpack @1.1.1.1

Then, I remove node_modules, and generate it once more using bundle exec rails webpacker:install. This time I've had node_modules/.bin/webpack file and the error was fixed.

@jakeNiemiec
Copy link
Member

@mtoygar Glad you could get it working, but remember that webpack should be installed to dependencies, not devDependencies. devDependencies will not be installed in a production environment and have caused problems for webpacker users in the past.

@mtoygar
Copy link

mtoygar commented Jun 20, 2019

thank you @jakeNiemiec , bundle exec rails webpacker:install adds it to dependencies but I will edit and clearify my comment.

@selivandex
Copy link

You need run task yarn install before assets:precompile.

Look at documentation

https://github.com/rails/webpacker/blob/master/docs/deployment.md

x1wins added a commit to x1wins/CW-OVP that referenced this issue Jul 9, 2020
x1wins added a commit to x1wins/CW-OVP that referenced this issue Jul 9, 2020
* feature/webpacker-error:
  Fixed Webpacker::Manifest::MissingEntryError error Command "webpack" not found. - bundle exec rails webpacker:install - rails/webpacker#522 (comment)
@dorianmariecom
Copy link
Contributor

when error happens with capistrano:

before "deploy:assets:precompile", "deploy:yarn_install"

namespace :deploy do
  desc 'Run rake yarn:install'
  task :yarn_install do
    on roles(:web) do
      within release_path do
        execute("cd #{release_path} && yarn install")
      end
    end
  end
end

@chrilleferna
Copy link

I followed Dorian's advice (adding a yarn_install to the production.rb deployment file), and that worked. Although I don't understand why this should be necessary at every deployment

@dorianmariecom
Copy link
Contributor

i also recommend adding node_modules to the linked_dirs for faster deploys:

append :linked_dirs, 'tmp/pids', 'tmp/sockets', 'log', 'node_modules'

@wdiechmann
Copy link

Had my self a wonderful workbench - until suddenly I got the "webpack not found" virus 😃

diff --git a/Dockerfile b/Dockerfile
index ff1273d..f064077 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,7 +10,7 @@ WORKDIR /app/hermes
 # nodejs and yarn
 RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
 RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
-RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
+RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
 RUN apt-get update && apt-get install -y nodejs yarn
 

I downgraded my node to 14.16 (originally c/p'ed a Dockerfile from some post online - and it did actually work wonders for quite some time but then all of a sudden; yeah I know - had to be me right - anyways) and did the "vax and sermon":

rails webpacker:install

- and in under 5min I was up and running about 😆

thx

KingTiger001 added a commit to KingTiger001/Rails-web-pack-project that referenced this issue Jan 15, 2023
* webpack or webpack-dev-server not found

Add to troubleshooting of readme to prevent such issues rails/webpacker#379 (comment), rails/webpacker#506

* Update README.md

* Update README.md

* Include solution for error occurring in heroku

* Update README.md

Since it is known that node buildpacks is not necessary Read: rails/webpacker#522 (comment)

* Update README.md

* Update README.md

Include instruction while upgrading from rails 4 to 5.

* Minor update

* Use ./bin/rails

* Add as comment
cool1209 pushed a commit to cool1209/cw_ovp that referenced this issue Jan 24, 2023
cool1209 pushed a commit to cool1209/cw_ovp that referenced this issue Jan 24, 2023
* feature/webpacker-error:
  Fixed Webpacker::Manifest::MissingEntryError error Command "webpack" not found. - bundle exec rails webpacker:install - rails/webpacker#522 (comment)
smartech7 pushed a commit to smartech7/ruby-webpacker that referenced this issue Aug 4, 2023
* webpack or webpack-dev-server not found

Add to troubleshooting of readme to prevent such issues rails/webpacker#379 (comment), rails/webpacker#506

* Update README.md

* Update README.md

* Include solution for error occurring in heroku

* Update README.md

Since it is known that node buildpacks is not necessary Read: rails/webpacker#522 (comment)

* Update README.md

* Update README.md

Include instruction while upgrading from rails 4 to 5.

* Minor update

* Use ./bin/rails

* Add as comment
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