Rails: Webpack-dev-server has unmet peer dependency - ruby-on-rails

I am currently trying to set up a Rails 6.0.2 application on Ubuntu 18.0.4 using Docker.
I have successfully set up the database using PostgreSQL and I have installed the necessary gems by running the command below:
bundle install
However, when I try to install the node packages using the command below:
yarn install
I get the message below which gives me some concern that something is not right:
warning " > webpack-dev-server#3.10.3" has unmet peer dependency "webpack#^4.0.0 || ^5.0.0".
warning "webpack-dev-server > webpack-dev-middleware#3.7.2" has unmet peer dependency "webpack#^4.0.0".
I have tried a few solutions but it's not working. I need some help. Thank you.

Here's how I solved:
Simply run the command below to upgrade the version of yarn to your desired version:
yarn upgrade webpack#^4.0.0
Note: You can substitute 4.0.0 with the required version for yarn, say 5.0.0.
Another Solution
Add the version of webpack that you want to your package.json file. Here the version of webpack used is 4.43.0:
"devDependencies": {
"webpack": "^4.43.0",
"webpack-dev-server": "^3.11.0"
}
And then run yarn install to install webpack
For Docker Applications only:
Add the command just before the yarn install command in your Dockerfile:
RUN yarn upgrade webpack#^4.0.0 \
yarn install
Reference to this on GitHub: Unmet peer dependencies
That's all.
I hope this helps.

I upgraded packages one at a time but kept getting the same warnings.
So I ran:
yarn upgrade
and next time I ran this all the warnings messages there were there previously had gone away:
yarn install

Related

Yarn Unknown Syntax Error: Unsupported option name ("--check-files")

When I try to run yarn install --check-files on a rails repo that I cloned I'm getting the following error:
Unknown Syntax Error: Unsupported option name ("--check-files").
$ yarn install [--json] [--immutable] [--immutable-cache] [--check-cache] [--inline-builds] [--mode #0]
I've tried updating yarn and node to the latest stable versions
I've tried deleting yarn/node modules and yarn.lock in the local folder and running yarn install again
I've tried yarn upgrade --latest which also brings up a similar error Usage Error: Couldn't find a script named "upgrade".
I'm currently using volta to manage my versions and have not had too much trouble up until now.
I've previously run --check-files on other repos with no problems.
Ok turns out my system was running yarn 3.* globally which was conflicting with my rails version (6.0.5). I had originally installed yarn using brew so I had to uninstall and start again with npm using the following steps:
brew uninstall yarn to remove yarn with brew
npm install -g yarn to install yarn with npm
yarn set version classic to set yarn version to 1.*
yarn -v to make sure I was on version 1.*

Yarn packages won't update for dependency issue

On a development server, for an application barely deployed, rails commands won't execute because of lack of integrity file.
error Couldn't find an integrity file
error Found 1 errors.
========================================
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.
========================================
Both
yarn install --check-files
yarn install
lead to the same error
compression-webpack-plugin#4.0.1: The engine "node" is incompatible with this module. Expected version ">= 10.13.0". Got "8.17.0"
Found incompatible module
Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The 'visit' prompt is unfortunately of no use, as it does not deal with the node engine.
Being barely deployed, there is no node-modules directory yet, which is expected. However on development machine there is the directory and no issues whatseoever in precompiling assets.
Server context:
node -v
> v8.17.0
How can this situation be unblocked?
you need to update the node to a version higher than the one mentioned >= 10.13.0 then re-install yarn and re-run the check:
if you're on Mac OS:
brew install node#14 && brew link --force node#14
brew install yarn
if you're on Linux:
cd ~
curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
then check if you have a compatible version
node -v
=> v14.2.0
``
if so re-run any of your commands:
```bash
yarn install --check-files
yarn install

Error upgrading dependencies in yarn.lock file with yarn up in Yarn 2.0

I'm trying to use Yarn 2.0 to upgrade to the latest version of the dependency in my yarn.lock to resolve a dependabot issue. The issue exists with the ini dependency and I tried running command yarn up ini which resulted in the following error:
❯ yarn up ini
Usage Error: Pattern ini doesn't match any packages referenced by any workspace
I noticed that I can use yarn up to upgrade packages in package.json file, but haven't been able to figure out how to update a dependency in a yarn.lock. I'm wondering if anyone knows what command I should be using instead?
Any help would be greatly appreciated. Thank you!
Documentation Source: https://yarnpkg.com/getting-started/migration#renamed
I learned that you can't upgrade individual dependencies in the yarn-lock file, you have to upgrade package with the dependency in the package.json file by running the command:
yarn up ${package_name} followed by yarn install in Yarn 2.0.
I noticed that I can use yarn up to upgrade packages in package.json file, but haven't been able to figure out how to update a dependency in a yarn.lock. I'm wondering if anyone knows what command I should be using instead?
Starting from 3.0, transitive dependencies (ie dependencies of dependencies) can be upgraded using yarn up -R <name>.

webpacker is not installed successfully on rails 4.2

Terminal: bash on Ubuntu on windows 10
Rails: 4.2.8
npm: 5.5.1
node: v8.9.1
yarn: 1.3.2
After rake webpacker:install, the console shows as follows. Although it shows "successfully installed" at the very end, some errors appear in the log. Is it normal?
create config/webpacker.yml
Copying webpack core config and loaders
create config/webpack
create config/webpack/development.js
create config/webpack/environment.js
create config/webpack/production.js
create config/webpack/test.js
Copying .postcssrc.yml to app root directory
create .postcssrc.yml
Copying .babelrc to app root directory
create .babelrc
Creating javascript app source directory
exist app/javascript
identical app/javascript/packs/application.js
Installing binstubs
run bundle binstubs webpacker from "."
append .gitignore
Installing all JavaScript dependencies
run yarn add #rails/webpacker coffeescript#1.12.7 from "."
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#rails/webpacker > postcss-cssnext#3.0.2" has unmet peer dependency "caniuse-lite#^1.0.30000697".
error An unexpected error occurred: "EINVAL: invalid argument, lstat '/mnt/d/Github/cfegame/node_modules/babel-core/package-lock.json'".
info If you think this is a bug, please open a bug report with the information provided in "/mnt/d/Github/cfegame/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Installing dev server for live reloading
run yarn add --dev webpack-dev-server from "."
yarn add v1.3.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "linux" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "webpack-dev-server > webpack-dev-middleware#1.12.1" has unmet peer dependency "webpack#^1.0.0 || ^2.0.0 || ^3.0.0".
warning " > webpack-dev-server#2.9.4" has unmet peer dependency "webpack#^2.2.0 || ^3.0.0".
error An unexpected error occurred: "EINVAL: invalid argument, lstat '/mnt/d/Github/cfegame/node_modules/camelcase-keys/node_modules/camelcase/license'".
info If you think this is a bug, please open a bug report with the information provided in "/mnt/d/Github/cfegame/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Webpacker successfully installed 🎉 🍰
When I "successfully installed" webpacker and I want to check if webpack-dev-server worked properly, the console shows as follows. Did it mean I don't install webpacker properly?
(home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `exec': No such file or directory - (project_dir)/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `block in execute_cmd'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:46:in `chdir'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:46:in `execute_cmd'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:11:in `run'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/runner.rb:6:in `run'
from (home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/exe/webpack-dev-server:8:in `<top (required)>'
from bin/webpack-dev-server:17:in `load'
from bin/webpack-dev-server:17:in `<main>'
basically yarn is managing your packages. He is trying to install the webpack-dev-server- with yarn add --dev webpack-dev-server from "." but it fails. This is the documentation about that yarn add command
npm is the alternative for using yarn for installing packages so in your server terminal run
npm install webpack-dev-server
and it should install the dependencies
When I "successfully installed" webpacker and I want to check if webpack-dev-server worked properly, the console shows as follows. Did it mean I don't install webpacker properly?
(home_dir)/.rvm/gems/ruby-2.3.3/gems/webpacker-3.0.2/lib/webpacker/dev_server_runner.rb:47:in `exec': No such file or directory - (project_dir)/node_modules/.bin/webpack-dev-server (Errno::ENOENT)
You either did not install it or your are searching the wrong path, maybe the gem is installed in .rvm/gems/ruby-2.3.3somethingelse
Some discussion you may want to read
https://github.com/Microsoft/WSL/issues/2448
https://github.com/yarnpkg/yarn/issues/4188

Grunticon & TravisCI

We are running into an issue when Grunticon is being installed into our Rails 4 engine on TravisCI. I'd appreciate any ideas on:
Making the path shorter for installing Grunticon in Rails
A way for TravisCI to skip installing Grunticon during our builds (we don't need it for testing)
A way to upgrade npm on TravisCI (rumor has it that npm v3 may solve this)
Error from Travis:
Gem::Package::TooLongFileName: File "node_modules/grunt-grunticon/node_modules/grunticon-lib/node_modules/directory-colorfy/node_modules/phantomjs/node_modules/fs-extra/node_modules/rimraf/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile" has a too long path (should be 256 or less)
An error occurred while installing trusty-convoy-extension (0.0.3), and Bundler
cannot continue.
Make sure that `gem install trusty-convoy-extension -v '0.0.3'` succeeds before
bundling.
The command "eval bundle install --jobs=3 --retry=3 --deployment --path=${BUNDLE_PATH:-vendor/bundle}" failed. Retrying, 2 of 3.
Grunticon is installed using a Gruntfile.js in our root directory. That triggers scripts in a node_modules directory. We followed this guide: https://github.com/filamentgroup/grunticon
Thanks!
Update: Successfully installed npm 3 on TravisCI.
before_install:
- npm install -g npm#3.x-latest
Sadly, did not fix the issue.
In your Travis preinstall..
npm i -g npm#3
Npm 3 is in late beta, and will give you a much more flat directory structure.
Note: you will need to add any peer dependencies to your package.json

Resources