How to use Create React App using Yarn 2? - create-react-app

In yarn v1 we initialize create react app using yarn create react-app my-app. How to initialize the same in yan v2.
The above command gives the error
Usage Error: No project found in <<directory>>
$ yarn run <scriptName> ...

Check your yarn version:
yarn --version
If it's below 1.22 you may need to upgrade it to use yarn 2:
npm install -g yarn
You can then create your app:
yarn create react-app my-app
cd my-app
yarn set version berry
yarn
yarn start
This should have your react app up and running using yarn 2. You may want to remove the node_modules folder:
rm -R node_modules
Also, you need the next line on .yarnrc.yml
nodeLinker: "node-modules"

You can use yarn dlx create-react-app my-app. It will work.
There are a lot of changes came with the yarn version2 update.
check this also for additional info: https://dev.to/arcanis/introducing-yarn-2-4eh1

Related

Global parameter does not work with yarn 3

My env:
- OS: Ubuntu 20.04
- Yarn: 3.1.1
- Node: v16.12.0
Instruction link: https://cli.vuejs.org/guide/installation.html
When I run command: yarn global add #vue/cli
I got error:
Usage Error: The 'yarn global' commands have been removed in 2.x - consider using 'yarn dlx' or a third-party plugin instead
$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...
The documentation contains instructions for yarn v1.
Yarn v2 and above no longer supports the use of the global parameter.
You can view their migration guide here.
You can use yarn dlx everytime you want to run a command with vue.
Alternatively, you can install the vue cli using npm:
npm install -g #vue/cli
Yarn has removed global in v3, according to its official document.
You can use the #vue/cli the same as npx using yarn dlx without installing it globally.
yarn dlx #vue/cli do_something

Error while creating react-native cli project

Error:
Error: Couldn't find the "C:\Users\Admin\AppData\Local\Temp\rncli-init-template-oScLDz\node_modules\react-native\template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template
Screenshot:
I have tried with npm using and it worked.
npx react-native init YourAwesomeProject --npm
After that
I have uninstalled yarn completely. Because you can install libraries using npm. So I have removed the yarn using
npm uninstall -g yarn
You can try:
Remove the global react-native CLI: npm uninstall -g react-native-cli or yarn global remove react-native-cli
And run again npx react-native init YourAwesomeProject
or
Run npx react-native-cli init YourAwesomeProject
Maybe these links can help:
https://github.com/react-native-community/cli#about
How to fix "Can not find module ".../template.config" error in React Native
surely you have your root a file or folder .yarn/ package.json package-lock.json
Remove them and try again rm -rf .yarn/ package.json .yarn/ package-lock.json

Can "yarn add global " update packages installed by npm?

I use yarn as package-manager but the first time I install nativescript I used;
npm install -g nativescript
Can I update the package using yarn add global nativescript?
NOTE: I run tns package-manager set yarn in my projects folder
Yes ;
yarn global add nativescript
and
yarn global upgrade
updates packages which are installed by npm
Please consider checking migrating from npm
Thanks to #Manoj for answer

Expo fails to build, Request failed with status code 400

I'm trying to build a project in expo react native project.
My expo version is 3.2.2, sdkVersion is 35.
When I ran in cmd (on Windows 10)
set EXPO_DEBUG=true
expo build:android -c
I got:
Request failed with status code 400
Error: Request failed with status code 400
at createError (C:\Users\Jonny\AppData\Roaming\npm\node_modules\expo-cli\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\Users\Jonny\AppData\Roaming\npm\node_modules\expo-cli\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\Users\Jonny\AppData\Roaming\npm\node_modules\expo-cli\node_modules\axios\lib\adapters\http.js:237:11)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
I'm tried to update expo version, sdkVersion, the version in react, check for internet connection.
Expo login and logout works fine. I don't have any proxy in my network.
I don't have any clues for what search or how to fix this problem.
Seems was a error in expo-cli version 3.2.2.
The update 3.2.3 fixed for me.
I have fixed the issue by using this command
Move to your root folder then type this command in your terminal
npm install -g expo-cli
I had two versions of expo-cli installed (one via yarn global install expo-cli and one as a dev dependency in project yarn add -D expo-cli). This started working for me after I removed the global expo-cli:
yarn global remove expo-cli
and used the local version in my project instead:
yarn run expo-cli start
Run those following command, then we are good to go.
$ yarn global remove expo-cli && yarn global add expo-cli
$ rm -rf node_modules/ yarn.lock && yarn install
$ yarn run start

NPM doesn't support PnP

I was trying use pnpm with create-react-app v2 as follows
npx create-react-app my-app --use-pnp
But it gives me following warning
NPM doesn't support PnP.
Falling back to the regular installs.
What should I do in order to use pnpm with create-react-app?
I already have pnpm installed globally using npm.
pnp is a Yarn feature, you need the latest version of yarn installed on your system to use it (at least Yarn 1.12).
Try
yarn create react-app project-name --use-pnp
And make sure yarn -v is >= 1.12