Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn install says up to date, yet can't start rails console

I've been developing an app using Webpack, Vue.js and Rails. No problems for two months, but out of nowhere when I try to start rails console rails c, yarn complains that packages out of date:

error An unexpected error occurred: "Unknown language key integrityNodeDoesntMatch".
info If you think this is a bug, please open a bug report with the information provided in "/Users/maksimfedotov/vras/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.


========================================
  Your Yarn packages are out of date!
  Please run `yarn install` to update.
========================================

Yet when I run yarn install:

yarn install v1.3.2
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.71s.

I've been looking through yarn and webpacker documentation, tried various yarn cleanup commands, but no luck.

Interestingly enough, I can still run the server, its only console that complains.

like image 464
Maxim Fedotov Avatar asked Apr 02 '18 11:04

Maxim Fedotov


People also ask

How do I fix install yarn error?

To solve the error "yarn: command not found", install the yarn package globally by running npm install -g yarn and restart your terminal. If the command fails, run it with sudo and make sure the correct PATH is set in your system's environment variable.

What is yarn install force?

yarn install is used to install all dependencies for a project. This is most commonly used when you have just checked out code for a project, or when another developer on the project has added a new dependency that you need to pick up.


4 Answers

This is an old issue, which has been resolved, so I am writing down what I did in the end:

Simply deleting node_modules usually solves the issue. If you are using spring, it also can mess this up, so consider running DISABLE_SPRING=1 rails s to see if that helps

like image 52
Maxim Fedotov Avatar answered Oct 16 '22 16:10

Maxim Fedotov


Try restarting spring by running spring stop.

This fixed the issue for me, and meant I didn't need to constantly prefix commands with the spring disable flag.

The above command stops spring: to check that it automatically restarted, run spring status.

Credit to this comment on GitHub for the solution!

like image 44
lucas Avatar answered Oct 16 '22 15:10

lucas


You can add in the config/environments/development.rb

this configuration setting

config.webpacker.check_yarn_integrity = false

It also it forget to check yarn integrity on every rails call, as migrations, launching consoles ..., in development environment

like image 35
anquegi Avatar answered Oct 16 '22 14:10

anquegi


This problem resurfaced in April 2021 due to compatibility issues between node-sass and node version 16. (I had similar problems here and provide a similar answer to that below here).

So my solution is to downgrade node until version 16 is fully compatible.

Install node 14 with nvm install 14, then set it to the global default with nvm alias default 14.

Then:

  1. Stop your rails server if it's running
  2. Open a fresh new terminal window (so that node --version returns 14.x (not 16)
  3. Run spring stop
  4. Delete yarn.lock
  5. Remove existing node modules with rm -rf node_modules
  6. Check that node --version returns 14. If it doesn't run nvm install 14 again.
  7. Now reinstall modules with yarn install (if you don't have yarn for node 14, install it with npm install --global yarn)
  8. It should succeed!
  9. Restart your rails server, and it will work!

Other useful info:

  • This github issue - this comment in particular
like image 1
stevec Avatar answered Oct 16 '22 16:10

stevec