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

Error Command "webpack" Not Found #9382

Closed
RuthNjeri opened this issue Mar 28, 2021 · 17 comments · Fixed by #9395
Closed

Error Command "webpack" Not Found #9382

RuthNjeri opened this issue Mar 28, 2021 · 17 comments · Fixed by #9395
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed high-priority

Comments

@RuthNjeri
Copy link
Contributor

Builds have been failing in the stable deployment due to the error error Command "webpack" not found

This seems to be a common error and there are some solutions as suggested below;

rails/webpacker#522 (comment)
rails/webpacker#522 (comment)

I am not sure what criteria we should use to pick a fix.

@RuthNjeri RuthNjeri added bug the issue is regarding one of our programs which faces problems when a certain task is executed high-priority labels Mar 28, 2021
@RuthNjeri
Copy link
Contributor Author

Do you have any thoughts on this @noi5e?

@anirudhprabhakaran3
Copy link
Member

Running

rails webpacker:install

on my local machine seems to solve this issue

@waridrox
Copy link
Member

As pointed out in the gitter channel by @noi5e -

bundle install
rails webpacker:install
rails webpacker:install:react
rails generate react:install

Running these commands solves the issue.

@jywarren
Copy link
Member

Is this related to the lack of manifest.js file as well?

I just added these notes to #3840 (comment) as @TildaDares noted this:

Noting that due to recent install of webpacker there's an extra step needed, apologies if this has caused you trouble!

For now, you have to create a manifest.js file, following the steps shown here: https://stackoverflow.com/questions/58339607/why-does-rails-fails-to-boot-with-expected-to-find-a-manifest-file-in-app-asse#answer-58370129:~:text=Easy%20Steps%20To%20Solve%20the%20Problem%3A

The error you may see for which this is the solution is:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/jeff/.gem/ruby/2.6.6/gems/mimemagic-0.3.8/ext/mimemagic
/Users/jeff/.rubies/ruby-2.6.6/bin/ruby -rrubygems
/Users/jeff/.gem/ruby/2.6.6/gems/rake-13.0.3/exe/rake
RUBYARCHDIR\=/Users/jeff/.gem/ruby/2.6.6/extensions/x86_64-darwin-20/2.6.0-static/mimemagic-0.3.8
RUBYLIBDIR\=/Users/jeff/.gem/ruby/2.6.6/extensions/x86_64-darwin-20/2.6.0-static/mimemagic-0.3.8
rake aborted!
Could not find MIME type database in the following locations:
["/usr/local/share/mime/packages/freedesktop.org.xml",

The steps are:

This error comes up because you don't have a manifest.js created. You need to create one, and add in a few lines to make sure things are working. In the old version of sprockets, they made big assumptions about which assets sprockets is taking care of (i.e. bundling and concatenating). Not anymore. Now you have to tell sprockets explicitly, what files you want taken care of: and you do this in your manifest.js file.

Create the manifest.js file

$ mkdir -p app/assets/config

$ touch app/assets/config/manifest.js (not the root rails directory)

Then copy and paste the following into the manifest.js file you just created:

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

If you have a precompile array in your app/config/ folder (see below for an example) e.g. app/config/production.rb then perhaps you should move them over to your manifest.js if they are not already accessed above.

config.assets.precompile = ["admin.js", "admin.css"]

Lastly, if you are using webpacker, you might want to decide what you want handled by the asset pipeline and what you want handled by webpacker. i.e. remove the link_directory to the javascripts file according to your own particular use cases.

i.e. is it possible these steps @waridrox copied in from @noi5e also solve the manifest issue? Just trying to coordinate around these various hiccups. Thanks all!

@waridrox
Copy link
Member

waridrox commented Mar 30, 2021

@jywarren I ran into the webpack problem after syncing my fork, and was able to resolve it with these commands -

bundle install
rails webpacker:install
rails webpacker:install:react
rails generate react:install

For now, you have to create a manifest.js file, following the steps shown here: https://stackoverflow.com/questions/58339607/why-does-rails-fails-to-boot-with-expected-to-find-a-manifest-file-in-?app-asse#answer-58370129:~:text=Easy%20Steps%20To%20Solve%20the%20Problem%3A

This I believe is for people trying to setup a new db altogether, with sqlite since they are running into problems with sql after the command db:setup
ERROR -

LoadError: Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? mysql2 is not part of the bundle. Add it to your Gemfile.

The workaround then is to do - cp config/database.yml.sqlite.example config/database.yml and some configuration required in manifest.js provided by the link above after running this command. Since I already had redis db setup, I didn't face the issue of creating a manifest.js file.

@noi5e
Copy link
Contributor

noi5e commented Mar 30, 2021

I just made an FTO at #9392 to update the installation docs for React & webpacker setup!

It's a distinct issue from this one, because as @RuthNjeri mentioned in the original post builds are failing over at stable. For that we'll need to ping @icarito, which I'll do in chat right now.

@jywarren
Copy link
Member

jywarren commented Mar 30, 2021 via email

@anirudhprabhakaran3
Copy link
Member

A quick search on StackOverflow provided me with these answers:

  1. bundle exec rails webpacker:install
  2. Upgrading the node version

Will any of these work?

@icarito
Copy link
Member

icarito commented Mar 30, 2021

A couple of weeks ago, webpacker was built correctly in our unstable staging instance.
https://jenkins.laboratoriopublico.org/job/Plots-Unstable/1098/console

I pushed unstable to a new branch and made a pull request to be able to compare the code:
https://github.com/publiclab/plots2/pull/9393/files

It looks to me like @anirudhprabhakaran3 is correct that the node version needs to be updated.

@jywarren
Copy link
Member

OK just noting that @icarito and i realized the GitHub diff is wrong - all those changes are already in our main branch. Also it seems to be building our stable branch fine in Jenkins, so something is odd with our main branch not building to stable.publiclab.org. Looking deeper...

@jywarren
Copy link
Member

Just noting that it seems to be written wrong in 3 places in the GitHub Actions config - webpack instead of webpacker:

run: bundle exec rails g webpack:install && bundle exec rails g webpack:install:react && bundle exec rails g react:install

@jywarren
Copy link
Member

I think stable.publiclab.org is building again!!!

@icarito
Copy link
Member

icarito commented Mar 30, 2021

Yup, I think #9395 did fix it.

@noi5e
Copy link
Contributor

noi5e commented Mar 30, 2021

Ah, great, I see. I put the commands in the wrong order. Thanks @icarito!

@noi5e
Copy link
Contributor

noi5e commented Mar 30, 2021

Just noting that it seems to be written wrong in 3 places in the GitHub Actions config - webpack instead of webpacker:

Oh yeah, I left a note about this in chat (but obviously it's easy to miss with all the activity lately):

It's meant to be rails webpacker:install:react instead of rails g webpack:install:react. 🤦 @jywarren You might want to take note, because we currently have 2 out of 3 wrong commands in the GitPod & test flows!

@jywarren
Copy link
Member

OK, i'll make that change in a pr, thanks @noi5e !!!

@RuthNjeri
Copy link
Contributor Author

Thanks, everyone! 🎉
Closing the issue since PRs referencing it have been merged 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed high-priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants