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

Webpacker is breaking webpack #1165

Closed
NicholasLYang opened this issue Jan 9, 2018 · 27 comments
Closed

Webpacker is breaking webpack #1165

NicholasLYang opened this issue Jan 9, 2018 · 27 comments

Comments

@NicholasLYang
Copy link

When I run webpack, I get the following error:

webpack config /Users/nicholas/cs_projects/content-editor/config/webpack/development.js not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment.

This appears to be a webpacker error. Why this is affecting webpack, I have no idea.

@ytbryan
Copy link
Contributor

ytbryan commented Jan 10, 2018

Did you follow the instruction: please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment.

Can you show us the repo and how you recreate this?

@NicholasLYang
Copy link
Author

NicholasLYang commented Jan 10, 2018 via email

@gauravtiwari
Copy link
Member

Webpacker is built in/for Ruby/Rails so don't think it will work outside of it.

@georgeclaghorn
Copy link

georgeclaghorn commented Jan 10, 2018

If you’re using Bash, your shell may have cached bin/webpack from a Rails project as the location of the webpack executable. It does this to avoid relatively costly $PATH searches.

Are you using Bash? If so, add set +h to your ~/.bash_profile to disable hashing, then open a new shell.

@NicholasLYang
Copy link
Author

Okay, I figured out the cause of the issue.

@gauravtiwari, I don't think you understood in the slightest my issue. I am NOT trying to use webpacker outside of Ruby or Rails, I am NOT even trying to use webpacker. I'm simply attempting to use Webpack, good, normal old Webpack, and your gem is breaking that.

@georgeclaghorn, thank you for that advice, made me remember that I can just look up the source of the executable with which webpack. Basically, webpacker installs two binstubs: webpack and webpack-dev-server. But guess what? That happens to be the exact commands that Webpack uses. Y'know, Webpack, the thing you guys are building on? So if you have the misfortune of installing Webpacker globally, which, I stupidly did, then you break Webpack. I'd highly suggest not doing that.

So yeah. Please don't name binstubs common executable names. It just creates a whole bunch of shadowing issues. Granted, I also have an npm issue at hand, but I do think naming your binstubs webpack and webpack-dev-server is asking for trouble. Why not webpacker and webpacker-dev-server?

@gauravtiwari
Copy link
Member

@NicholasLYang Forgive me but this is what you wrote:

Comment1:

When I run webpack, I get the following error:

webpack config /Users/nicholas/cs_projects/content-editor/config/webpack/development.js not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment.

This appears to be a webpacker error. Why this is affecting webpack, I have no idea.

Comment2:

No. This is not a Rails specific issue. I’m trying to run webpack in a
completely non Rails, non Ruby context (writing an npm package). Running
`bundle exec rails webpacker:install` will do nothing.

I’m trying to run webpack in a
completely non Rails, non Ruby context (writing an npm package

I hope you understand that the above is not enough information to tell anything about the problem you are having.

@gauravtiwari
Copy link
Member

Perhaps, consider uninstalling webpacker gem to remove executables from global namespace?

gem uninstall webpacker

@rossta
Copy link
Member

rossta commented Jan 10, 2018

@NicholasLYang Thank you for surfacing this issue. Your suggestions make sense. But, whether it was intended or not, it would be easy to interpret the wording of some of your comments as a bit harsh or, at best, unnecessarily sarcastic. Please consider the maintainers of this project are doing everything they can with what little time they have to help and respond to issues like yours and others as well.

@NicholasLYang
Copy link
Author

@gauravtiwari, yes I uninstalled Webpacker. Didn't fix my issue, but at this point, that's not Webpacker's fault, so not going to post it here. I'm not entirely sure how "I'm trying to run webpack in a completely non Rails, non Ruby context" is ambiguous, since I didn't say "I'm trying to run webpacker in a completely non Rails, non Ruby context", which would be rather confusing. Nonetheless, I do see that I was unnecessarily vague in my first post. I'll try to be more clear from now on. To clarify, I was attempting to run Webpack, the Javascript library for bundling, but Webpacker, the Ruby wrapper for the Javascript library, was interfering with it.

@rossta Fair point, I'm sorry. I find it very frustrating that a tool that came with Rails is breaking a fair portion of my JavaScript projects. More than a little harmful to productivity. Thank you for all the work you guys put into making Rails great.

@anthonymakela
Copy link

I have this same issue how can i fix it?

@gauravtiwari
Copy link
Member

gem uninstall webpacker

@niksosf
Copy link

niksosf commented Feb 18, 2018

@NicholasLYang
I had the same problem. I was trying out Webpacker in another branch and upon switching back out of that branch, your original error message appeared. a quick which webpack found it in /user/nik/.rvm/gems/ruby-2.4.1@sync/bin/webpack. A gem uninstall webpacker, which also prompted for removal of these two executables, did the trick. Hope that helps

@mwinslow331
Copy link

mwinslow331 commented Feb 26, 2018

Hello everyone - I've been primarily developing with Ruby/Rails for the past year and encountered the same problem. When I run which webpack it shows as a .gem in my user directory. Would I need to run gem uninstall webpacker in this directory then reinstall it under the directories where my Ruby projects are at in order to avoid getting this error for non-Ruby projects in the future?

Edit: I was able to resolve my issue so this does not need a response.

@ViggoV
Copy link

ViggoV commented Mar 6, 2018

Is there a way to reset the global reference after uninstall? I uninstalled, but now my webpack projects ignore the webpack entry in their package.jsons and instead fails, stating that the /Users/me/ruby-x.x.x/bin/webpack doesn't exist.. It is completely loudacris, in my humble opinion, to override the global webpack installation with a ruby gem and for the same reason I'll not use webpacker again.

@gauravtiwari
Copy link
Member

@ViggoV The global executables are removed in latest release. You would need to update binstubs after update, please see changelog.

bundle update webpacker
yarn add @rails/webpacker
bundle exec rails webpacker:binstubs # should replace old exe

@pjatx
Copy link

pjatx commented Apr 30, 2018

I think I'm stuck in purgatory. When I try the steps above, I still run into the following when trying to run webpack

	2: from /Users/philipjohnson/.rbenv/versions/2.5.0/bin/webpack:23:in `<main>'
	1: from /Users/philipjohnson/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/philipjohnson/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem webpacker (>= 0.a) with executable webpack (Gem::GemNotFoundException)

@gauravtiwari
Copy link
Member

@pjatx Have you updated the gem to the latest version? (make sure it's has new version specified in Gemfile)

@pjatx
Copy link

pjatx commented Apr 30, 2018

@gauravtiwari Yeah, this is actually not a rails project as other posters have mentioned.

I did uninstall webpacker, then ran into this and did the following with no success:

  1. Created a gemfile
  2. Added webpacker to gemfile
  3. Bundled it
  4. Followed the steps in your last post
  5. Tried to run webpack and received the above error
  6. Uninstalled webpacker again and ran webpack - same thing

I didn't, however, specify a version of webpacker. Should I try the above again doing so?

@gauravtiwari
Copy link
Member

@pjatx Ahh, sorry totally forgot.

Is it possible you might have multiple versions of webpacker installed in different ruby versions?

@pjatx
Copy link

pjatx commented Apr 30, 2018

@gauravtiwari Yeah it's definitely possible - I use rbenv to as my Ruby version manager

@ytbryan
Copy link
Contributor

ytbryan commented Apr 30, 2018

Curious, "this is actually not a rails project" May I know which ruby project is this? @pjatx

update: ok, got you. You used webpacker and it breaks your webpack.

@pjatx
Copy link

pjatx commented Apr 30, 2018

@ytbryan It's not a ruby project either - it's all javascript / templates.

@renchap
Copy link
Contributor

renchap commented Apr 30, 2018

This is because you still have the webpacker shim installed by rbenv in your shell's $PATH: /Users/philipjohnson/.rbenv/versions/2.5.0/bin/webpack

First you need to uninstall Webpacker as it seems to have been installed globally: gem uninstall -a webpacker.
Then, if not already deleted, you can safely remove it: rm /Users/philipjohnson/.rbenv/versions/2.5.0/bin/webpack

@pjatx
Copy link

pjatx commented May 1, 2018

Thanks @renchap that finally fixed my issue!

@justin808
Copy link
Contributor

Any chance that the rails app's bin/webpack can have a different name so as not to conflict? This one has hit me as well, and many others.

@gauravtiwari
Copy link
Member

@lain0
Copy link

lain0 commented Jan 6, 2021

run ./node_modules/webpack/bin/webpack.js
or make Makefile with

webpack:
    ./node_modules/webpack/bin/webpack.js

and run make webpack

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