rails 6 and vue.js new project fails - ruby-on-rails

Just following the tutorial below to integrate rails 6 with vue:
https://medium.com/#akshaych2786/vue-js-with-rails-6-and-performing-crud-operations-b043ef3691f2
But then rails fails to run. This is with no changes to the project, just following the tutorial. Some sort of dependency madness, but i'm new to vue and don't really understand what the issue is. And yes, i did run yarn install --check-files, same error. And yes, if i set check_yarn_integrity to false, then it works fine. But i'm not sure if i'm going to get into trouble by disabling this check.
$ rails g controller Welcome index
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.1.4`.
========================================
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.
========================================
To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).
yarn check v1.22.4
success Folder in sync.
Done in 0.18s.
yarn check v1.22.4
error "vue-loader##vue/component-compiler-utils#lru-cache#yallist" is wrong version: expected "^2.1.2", got "3.1.1"
error Found 1 errors.
info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.

Related

Installing Tailwind to Ruby on Rails 6 | The engine "node" is incompatible with this module

When installing Tailwind-CSS, I ran this command
yarn add tailwindcss#npm:#tailwindcss/postcss7-compat postcss#^7 autoprefixer#^9
I got this error message, which tells me to update node to a compatible version.
**error** tailwindcss#2.1.2: The engine "node" is incompatible with this module. Expected version ">=12.13.0". Got "10.24.1"
So how do I update node properly?
I am using Ruby on Rails 6
Update
When I updated node, I ran into a subsequent problem. This is what I ran to update node
nvm install 12.22.1
Now when I try to install Tailwind-CSS, I get a different error message.
Command 'yarn' not found
So then I ran nvm use 10.24.1 and I am back to square one.
When you install via yarn, append
--ignore-engines
So the full installation command is
yarn add tailwindcss#npm:#tailwindcss/postcss7-compat postcss#^7 autoprefixer#^9 --ignore-engines
I don't know why this works, but it does

First Rails project: Problem installing yarn

I am trying to get started with Rails, following the guide at https://guides.rubyonrails.org/getting_started.html, but I'm running into problems.
I've got ruby, sqlite3, and rails installed as required, and then run
rails new blog
as indicated in section 3.2 of the tutorial. I get an error saying "Your user account isn't allowed to install to the system RubyGems.", but I can install the gems into ./vendor/bundle, as suggested (I don't have full root access on this machine).
So far, so good. But then
rails webpacker:install
is run by the process, which gives me the following message:
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Of course, I went to that website and checked the instructions for my Fedora system and tried to follow them. The problem is again: I have limited root access, I cannot run the suggested commands; in particular, I cannot write to /etc/yum.repos.d/yarn.repo.
I also googled a bit, and what I could do is following https://developer.fedoraproject.org/tech/languages/nodejs/nodejs.html to install Node.js and Yarn (including setting the alias yarn for nodejs-yarn). But still, running
rails webpacker:install
says that Yarn is not installed.
Any help is greatly appreciated, I have to admit that I don't really know what I'm doing. Thanks!
On linux, the sudo command is the intended way to temporarily elevate user privledges.
wget https://yarnpkg.com/install.sh
sudo ./install.sh
That should get Yarn installed for you. The other problem it seems your having is installing ruby gems. You should be able to write to the vendor directory of your application by default, so make sure that you're doing this project in your /home/<MY USER NAME HERE> directory.

RubyMine's run config results in error that "Yarn requires Node.js 4.0" on Ubuntu

On my Elementary OS machine (an Ubuntu-based OS), after creating a new Ruby on Rails project with rails new yarntest and loading it in RubyMine, I could not launch it with RubyMine's "Development: yarntest" run configuration. The output was:
=> Booting Puma
=> Rails 6.0.1 application starting in development
=> Run `rails server --help` for more startup options
Yarn requires Node.js 4.0 or higher to be installed.
========================================
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.
========================================
To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).
However, running rails server in the console worked.
I tried reinstalling Yarn, but it still did not work.
I could only disable the Yarn integrity check in the Ruby on Rails config as stated in the error message (deleting the yarn.lock also appeared to work, but is surely wrong). Similarly, I did not want to track down and remove the different Yarn version, as suggested on another question, since the issue was with RubyMine.
I came across an answer on another question that mentioned this error message when running sudo yarn install (i. e. in sudo mode). I tried running sudo yarn install and could finally reproduce the error message outside of RubyMine's run config. Apparently, when running in sudo mode, the yarn binary was outdated.
The solution is therefore to point RubyMine to the correct yarn binary.
The easiest way to do that is to launch RubyMine from the terminal with rubymine, as pointed out by Olivia. See the related JetBrains ticket.

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.
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
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!
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
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:
Stop your rails server if it's running
Open a fresh new terminal window (so that node --version returns 14.x (not 16)
Run spring stop
Delete yarn.lock
Remove existing node modules with rm -rf node_modules
Check that node --version returns 14. If it doesn't run nvm install 14 again.
Now reinstall modules with yarn install (if you don't have yarn for node 14, install it with npm install --global yarn)
It should succeed!
Restart your rails server, and it will work!
Other useful info:
This github issue - this comment in particular
Try just yarn install then rails c again
If you are switching branches which change yarn.lock and just want to run a rails console without having to keep running yarn install everytime you switch, you can add this to your app/config/development.rb
config.webpacker.check_yarn_integrity = ENV['SKIP_YARN'].nil?
Then when rails complains you can simply do this
SKIP_YARN=true rails c
In my case, this solve the problem.
rm -rf yarn.lock
yarn install
Try this: NODE_ENV=development yarn install

(React on Rails) The engine "node" is incompatible with this module. Expected version "..."

For those familiar with the react-on-rails gem, or more generally, yarn:
Just today I updated my Node version to 8.8.1 via Homebrew. Now, when I attempt to run bundle && yarn && foreman start -f Procfile.dev (or just yarn install), I get the following message:
error react-webpack-rails-tutorial#0.0.1: The engine "node" is
incompatible with this module. Expected version "5.10.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation
about this command.
This is likely a very simple issue I am running into, but I have been unable to fix it after a few hours of debugging.
I tried manually updating my Node version in package.json to be that on my computer (did not seem to take effect whatsoever), downgrading my version to 5.10.0 via Homebrew (but was unable to), and even upgrading to the latest version of the gem which meant installing webpack as well.
No matter what I did, my local server startup (bundle && yarn && foreman start -f Procfile.dev) still lead to the same error above. Any ideas for this poor soul?
For anyone running into this same issue, I have not found a solution for the underlying issue but I have found a temporary workaround.
Simply run
bundle && yarn --ignore-engines && foreman start -f Procfile.dev
instead of
bundle && yarn && foreman start -f Procfile.dev
I hope this helps someone else that may have found themselves stuck in the same situation!
You need to update your Node.js version. Try to
Clear NPM's cache:
sudo npm cache clean -f
Install a little helper called 'n'
sudo npm install -g n
Install latest stable Node.js version
sudo n stable
I give you this list of checks to do from the react-webpack-rails-tutorial github page
Basic Demo Setup
Be sure that you have Node installed! We suggest nvm, with node version v6.0 or above. See this article Updating and using nvm.
git clone git#github.com:shakacode/react-webpack-rails-tutorial.git
cd react-webpack-rails-tutorial
Check that you have Ruby 2.3.0 or greater
Check that you're using the right version of node. Run nvm list to check. Use 5.5 or greater.
Check that you have Postgres installed. Run which postgres to check.
Use 9.4 or greater.
Check that you have qmake installed. Run which qmake to check. If
missing, follow these instructions: Installing Qt and compiling
capybara-webkit
Check that you have Redis installed. Run which redis-server to
check. If missing, install with Homebrew (brew install redis) or
follow these instructions.
bundle install
brew install yarn
yarn
rake db:setup
foreman start -f Procfile.hot
Open a browser tab to http://localhost:3000 for the Rails app
example with HOT RELOADING
Try Hot Reloading steps below!
foreman start -f Procfile.static
Open a browser tab to http://localhost:3000 for the Rails app
example.
When you make changes, you have to refresh the browser page.

Resources