use-yarn thinks I'm not using yarn - node.js

I have an app that uses yarn. I was having trouble with a yarn install... script. I tried a bunch of things, including using nvm to switch node versions. After that, I had a bunch of yarns installed and was still seeing the same unrelated issue (network issue pulling a dependency). So, I decided to switch back to the latest version of node and try something else. But, that introduced a new issue.
The yarn script stopped working completely. I'm using yarn install:deps and the result is to first run the preinstall script which does npx use-yarn and that errors and blocks continuation of the script. It says I'm not using yarn, though my command is yarn install:deps and which yarn shows that I am indeed running yarn.
How do you fix this?

Related

ERROR [PackageLoader] No driver (HTTP) has been selected. In order to take advantage of the default driver

I was following a tutorial on Udemy Execution using npx ts-node-dev src/main.ts I get the error [PackageLoader] No driver (HTTP) has been selected. In order to take advantage of the default driver, please, ensure to install the "#nestjs/platform-express" package ($ npm install #nestjs/platform-express). I tried uninstalling and reinstalling #nestjs/platform-express but I still get same error.
I tried many time to run this command $ npm install #nestjs/plateform-express but I still face this issue.
Ok. It was caused by hoisiting packages by Yarn. Because of different versions, platform-express went to top when other nestjs packages stayed in the deep level folder.

Yarn erased my node_modules folder, every time

I just recently successfully changed to using yarn on one of my systems, replacing npm, for my react-native projects. used yarn version 1.22.11.I ran it and it resolved dependencies beautifully and there were no problems.
So I copied the project over to another computer. I wanted to do the same thing -- use yarn with it-- but when I run the 'yarn' command, instead of going through my directory and fixing my dependencies...
...yarn goes through my directory and deletes not only the files, but the folders!! This is yarn version 2.4.1.
Anyone have thoughts about why this might happen?
yarn 2 does not use or create node_modules directory by default, instead it uses a new technology called plug 'n play (pnp). If you upgrade to yarn 2.x from yarn 1.x it will delete the node_modules folder.
For a primer on yarn 2 and pnp, see https://dev.to/arcanis/introducing-yarn-2-4eh1 and https://yarnpkg.com/features/pnp
If you want to turn off pnp in yarn 2 and use node_modules, see: How to turn off yarn#2 PnP?
But most of the community has stuck with yarn 1.x. See https://blog.hao.dev/state-of-yarn-2-berry-in-2021
You may decide to stick with yarn 1.x, return to npm, or try yarn 2.x berry with or without pnp. In general, if your project can work with pnp, it is much faster. However, many packages in the javascript ecosystem are incompatible.
Update 2022: Yarn 3.x is now available, and is easier to update to than yarn 2. pnpm is now also an interesting choice.

Different NPM version used when generating React app

When I try to create the starter React tutorial app using powershell, I get the below error:
"You are using npm 2.15.12 so the project will be boostrapped with an old unsupported version of tools".
"Please update to npm 3 or higher for a better, fully supported experience".
However, my NPM version is 6.11.3 as seen below.
What I have tried:
I have ran powershell as admin as answered in this question and restart.
I have also uninstalled and reinstalled Nodejs completely.
So after an extra hour digging around, I saw a few posts with similar (but not exactly) the same issue. I decided to install Yarn and install with that.
After install, I ran yarn cache clean and ran npx create-react-app your-app and it worked. Sorry for bothering you all.
I had the same problem. I'm running WSL with ubuntu, and yarn cache clear didn't work, but I noticed a node modules directory created in the project. I think it was messing with the node version so I deleted it. It worked

Is it me or yarn?

apt works great for me. Rarely a problem and always easy to fix.
conda works great for me. Rarely a problem and always easy to fix.
I can't seem to get yarn to work...ever. Always some strange problem with node version or gyp libraries. Even when I get all of that fixed I get lots of warnings and then errors like
error An unexpected error occurred: "ENOENT: no such file or directory, lstat '/home/balter/.cache/yarn/v4/npm-tar-fs-1.16.3-966a628841da2c4010406a82167cbd5e0c72d509/node_modules/tar-fs/test/fixtures/a/hello.txt'".
Turns out if I run yarn install again there is a different file it can't find. Just for fun, I did
for i in {1..100}; do yarn install; done
Yup it errored on a different file every time, but never did "work."
Is it me, or is yarn just really fragile? If I want to install a package from github and the install instructions use yarn, is there a way around using yarn?
Also, no tag for "yarn"
I had the same problem in WSL one time and fix that using yarn cache clean
I was getting this same frustrating and hard to debug error. The problem in my case seemed to be yarn workspace behaviour caused by different versions of the same dependency in different packages (specifically ava versions 2 and 3). Only once I'd upgraded all occurrences of ava to their latest did I stop getting this error.
I was running into this same problem on Windows 10. I tried yarn cache clen because I saw that the tar-fs dependency was corrupted on disk going into the cache path (C://...AppData/Local/Yarn/Cache/npm-tar-fs...).
I saw that using yarn cache clean was deleting all cache files except for this one that was corrupted. I also tried deleting it manually and Windows wasn't allowing it.
So the solution was going into cmd and deleting it from there using the command DEL /F /Q /A <File Path>.
After that I ran yarn install again and it worked!

ec2 hangs on npm install

I have free tier ec2 (1GB RAB, 500MB swap memory)
When Jenkins performs npm install on the project, ec2 just hangs, stops responding and only reboot brings it to life.
With htop, I analysed the situation and figured out that RAM just exhausts and chokes and additional swap memory I created doesn't help.
Since I'm having a school project, I want to use free tier and somehow launch the project there (I tried npm run build too, but for now it has too many issues).
I tried yarn too, but there's an issue with different versions of babel-loader being required by two other packages.
Is there a way to perform npm install in an automatic fashion (so that Jenkins can do it with just a script shell) and without hanging ec2?
I ran into the same problem where the server just would stop installing. While it is definitely possible to upload the node_modules manually, I preferred to let npm do it for me. I solved it by deleting half of the dependencies before running npm install. After it finished i added them back and ran npm install a second time. Now everything is installed.
From now on npm install should work fine, since most dependencies are already installed. However adding or updating many dependencies at once might result in a hanging server again.

Resources