Webpacker: Can`t install webpacker in a rails existing rails 4 application.

Created on 8 Jun 2018  ยท  11Comments  ยท  Source: rails/webpacker

I followed all the steps given my read me.

When i run bundle exec rake webpacker:install i got.

`Running via Spring preloader in process 57093
identical config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying .postcssrc.yml to app root directory
identical .postcssrc.yml
Copying .babelrc to app root directory
identical .babelrc
Creating JavaScript app source directory
exist app/javascript
identical app/javascript/packs/application.js
apply /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/install/binstubs.rb
Copying binstubs
exist bin
identical bin/webpack
identical bin/webpack-dev-server
Adding configurations
append .gitignore
Installing all JavaScript dependencies
run yarn add @rails/[email protected] --tilde from "."
yarn add v1.7.0
[1/4] ๐Ÿ” Resolving packages...
[2/4] ๐Ÿšš Fetching packages...
[3/4] ๐Ÿ”— Linking dependencies...
warning " > [email protected]" has unmet peer dependency "css-loader@*".
warning " > [email protected]" has incorrect peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected]" has incorrect peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
[4/4] ๐Ÿ“ƒ Building fresh packages...

success Saved 0 new dependencies.
โœจ Done in 6.17s.
Installing dev server for live reloading
run yarn add --dev [email protected] from "."
yarn add v1.7.0
[1/4] ๐Ÿ” Resolving packages...
[2/4] ๐Ÿšš Fetching packages...
[3/4] ๐Ÿ”— Linking dependencies...
warning "@rails/webpacker > [email protected]" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > [email protected]" has unmet peer dependency "css-loader@*".
warning " > [email protected]" has incorrect peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected]" has incorrect peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
[4/4] ๐Ÿ“ƒ Building fresh packages...
success Saved 0 new dependencies.
โœจ Done in 5.20s.
Webpacker successfully installed ๐ŸŽ‰ ๐Ÿฐ`

Then when i run ./bin/webpack-dev-server i got.

/Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/dev_server_runner.rb:47:inexec': No such file or directory - /Users/Eduardo/social-wave/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
from /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/dev_server_runner.rb:47:in block in execute_cmd' from /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/dev_server_runner.rb:46:inchdir'
from /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/dev_server_runner.rb:46:in execute_cmd' from /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/dev_server_runner.rb:11:inrun'
from /Users/Eduardo/.rvm/gems/ruby-2.3.0/gems/webpacker-3.5.3/lib/webpacker/runner.rb:6:in run' from ./bin/webpack-dev-server:15:in

'`

The npm_modules folder is not being created in my project folder. I see in some place that a file named packages.json would be created, but i can`t find in my project.

Can someone help me solve this? I tried lots of different things in my project, but nothing work.

Most helpful comment

I cannot install this in an existing 4.2 Rails application:

~/code/cti >bundle exec rake webpacker:install
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
rake aborted!
Webpacker configuration file not found /Users/sshaw/code/cti/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/sshaw/code/cti/config/webpacker.yml
/Users/sshaw/.rvm/gems/ruby-2.3.5-railsexpress/gems/webpacker-3.5.5/lib/webpacker/configuration.rb:79:in `rescue in load'

Docs need to mention that if rails new is not used...
one must manually add config/webpacker.yml

All 11 comments

Have you tried re-running yarn to ensure that the correct packages are installed? That error suggests that the webpack-dev-server bin file wasn't installed in your project's node_modules directory.

I cannot install this in an existing 4.2 Rails application:

~/code/cti >bundle exec rake webpacker:install
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
rake aborted!
Webpacker configuration file not found /Users/sshaw/code/cti/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/sshaw/code/cti/config/webpacker.yml
/Users/sshaw/.rvm/gems/ruby-2.3.5-railsexpress/gems/webpacker-3.5.5/lib/webpacker/configuration.rb:79:in `rescue in load'

Docs need to mention that if rails new is not used...
one must manually add config/webpacker.yml

Please run rails webpacker:install...

Note that this does not work in 4.2. One must use Rake.

I'm running into the same missing webpacker.yml error when adding webpacker 4 to an existing rails 5.2.1 app. Seems like a gap.

@gj even after a clean install (rm -rf node_modules/; yarn) I don't see a node_modules/webpack-dev-server. I also don't see webpack-dev-server in yarn.lock. Is webpacker missing a development dependency?

@sshaw Using rake gets a small mention in the readme. Look under on rails version < 5.0 in https://github.com/rails/webpacker#installation

After some digging on the stacktrace, it looks like I have a different issue than @zhorn. Sorry for hijacking your issue.

This might help @sshaw. The webpacker:install template isn't reached because when rails initializes, the railtie's yarn integrity initializer tries to look up a value in webpacker.yml if a yarn.lock exists. I simply deleted yarn.lock to short-circuit the config file lookup (see below) and the template was reached.

https://github.com/rails/webpacker/blob/c2d032ccb41a811d6922e672fe219092b8ea1e6a/lib/webpacker/railtie.rb#L32

I'll move my conversation about the integrity check to https://github.com/rails/webpacker/issues/1135

@zhorn did you solve the problem? Can this issue be closed now?

For anyone else struggling with this: are you trying to install webpacker for the first time alongside react-rails?

I ran into this today on Ruby 2.3.0 & Rails 4.2.10. I discovered that the react-rails gem attempts to call a number of Webpacker.config methods on startup. These methods will fail if there's no webpacker.yml file.

I'm exploring a PR to one or both of these gems (I'm not sure where the responsibility should really lie yet), but in the meantime you may be able to overcome this by removing react-rails from your Gemfile, running bundle install, and then running rake webpacker:install. It should be safe to re-add react-rails after this initial install.

Try rails webpacker:install

am not sure if it supports old versions of rails

I had this issue because I didn't have yarn. I just removed the repo and reinstalled after brew install yarn

same as me but in case im just remove some this line on my Gemfile

gem 'webpacker', '~> 4.0'

Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks

Remove it and rails server up.

same as me but in case im just remove some this line on my Gemfile

gem 'webpacker', '~> 4.0'

Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks

Remove it and rails server up.

Thanks so much!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankFang picture FrankFang  ยท  3Comments

pioz picture pioz  ยท  3Comments

suhomozgy-andrey picture suhomozgy-andrey  ยท  3Comments

suhomlineugene picture suhomlineugene  ยท  3Comments

iChip picture iChip  ยท  3Comments