webpacker: bin/webpack-dev-server results in Cannot find module 'webpack-cli/bin/config-yargs'
On a fresh Rails 5.1.5 app with Ruby 2.5.0 and Node 9.5.0, running bin/webpack-dev-server
results in:
$ ./bin/webpack-dev-server
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:557
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (.../appname/node_modules/webpack-dev-server/bin/webpack-dev-server.js:64:1)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
The suggested fix — yarn add webpack-cli -D
— works. It seems like webpack-cli should be part of the default packages.json
installed by Webpacker.
"devDependencies": {
"webpack-cli": "^2.0.9",
"webpack-dev-server": "^3.0.0"
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 70
- Comments: 25 (8 by maintainers)
Commits related to this issue
- Remove webpack-dev-server upgrade In the Upgrade section the readme had `yarn upgrade webpack-dev-server --latest`. This will cause issues related to https://github.com/rails/webpacker/issues/1295 un... — committed to natevick/webpacker by deleted user 6 years ago
- Remove webpack-dev-server upgrade (#1356) In the Upgrade section the readme had `yarn upgrade webpack-dev-server --latest`. This will cause issues related to https://github.com/rails/webpacker/issues... — committed to rails/webpacker by deleted user 6 years ago
- adding yarn add webpack-cli -D because of https://github.com/rails/webpacker/issues/1295 — committed to nodeEnthu/js_modules by deleted user 6 years ago
- Resolve Webpack Dev Server Issue Fix version mismatch for webpack dev server based on issue at https://github.com/rails/webpacker/issues/1295. — committed to MAPC/digitalhub by mzagaja 4 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev-server` integration for some reason, possibly ... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Run `app:update` and accept meaningful changes - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Run `app:update` and accept meaningful changes - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Run `app:update` and accept meaningful changes - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Run `app:update` and accept meaningful changes - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Upgrade Rails to 6.1(.1) - Bump Rails to 6.1.1 and update dependencies - Run `app:update` and accept meaningful changes - Remove Yarn dependency on `webpack-cli` This broke Rails 6.1's `webpack-dev... — committed to DFE-Digital/teaching-vacancies by csutter 3 years ago
- Remove webpack-dev-server upgrade (#1356) In the Upgrade section the readme had `yarn upgrade webpack-dev-server --latest`. This will cause issues related to https://github.com/rails/webpacker/issues... — committed to KingTiger001/Rails-web-pack-project by KingTiger001 6 years ago
- Remove webpack-dev-server upgrade (#1356) In the Upgrade section the readme had `yarn upgrade webpack-dev-server --latest`. This will cause issues related to https://github.com/rails/webpacker/issues... — committed to smartech7/ruby-webpacker by deleted user 6 years ago
In webpack 4.0.1 we need to run
yarn add webpack-cli -D
and it works!!!I think this is broken, because the package.json that comes with a fresh install gives me:
But meanwhile, webpack-dev-server from 3.0.0 on claims that:
https://github.com/webpack/webpack-dev-server/releases/tag/v3.0.0
EDIT: Doing
yarn add webpack-dev-server@^2.11.1
fixed it for me.Please run:
yarn add webpack-dev-server@^2.11.1
Hi @tuteurprive, welcome!
You may be assuming that Rails works the same way as Node projects. But Rails is slightly different in a better way. Here is an incomplete checklist:
gem "webpacker"
at your Gemfile?app/views/pages/index.html.erb
, do you have<%= javascript_packs_tag "something"%>
2a if you do not have a root, but want to generate a
"pages"
simply runrails g scaffold pages
and follow byrails db:migrate
rails server
to get the Rails server running. note: it’s not yarn run dev.Visit http://localhost:3000 and you should have something working.
Alternatively, start a fresh project by typing these at your terminal.
At
app/views/pages/index.html.erb
replace all the text with<%= javascript_packs_tag "hello_vue" %>
At route.rb, make sure you have this.
Run
rails server
and visit http://localhost:3000Let me know if it works. Alternatively, you should post to stackoverflow.com and tag it as
webpacker
.Try:
yarn add webpack-dev-server@2.11.1
Why it is not in docs?
@icechenfei First add
npx webpack-cli
and then runnpm run start
. In your package.json add"scripts": { "dev": "webpack --mode development", "build": "webpack --mode production", "start": "webpack-dev-server" }
Webpacker doesn’t support/ship with webpack 4.0 at the moment. Will update docs once this is done.
I had the same issues, however, none of the above solutions worked. I ended up patching a bit the
DevServerRunner
to use the now standardwebpack serve
instead ofwebpack-dev-server
:Works like a charm 😃
For rbenv users, here’s how to find where to apply the patch (be careful, this will be changed for every projects!):
isn’t work with added as development
@olivierlacan Thanks for filing the issue. It seems like dev server 3.0.0 doesn’t work with older versions of webpack - https://github.com/webpack/webpack-dev-server/releases
We need to update webpacker so it supports webpack v4.
hello ytbryan !
Many thanks for your help ! It’s really reassuring to see that one can get such precise help ! I have followed your suggestions (together with a friend of mine who is lot more experienced in coding) and it worked. I think webpacker was not properly installed / working !
Many thanks, problem solved !
Best !