Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native: switch from yarn to npm

Tags:

Is there a step-by-step process to change a react-native project from using yarn as the package manager to using npm? All I can find after several days of searching are instructions to go from npm to yarn and a package called deyarn which doesn't seem to fully work for me. Does anyone have a good resource on this?

like image 334
cbutler Avatar asked Jul 09 '18 06:07

cbutler


People also ask

Can I use npm instead of yarn?

Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node. js module resolution algorithm.

Is yarn still better than npm 2022?

In terms of speed and performance Yarn is better than NPM because it performs parallel installation. Yarn is still more secure than NPM. However, Yarn uses more disk space than NPM.

Is yarn better than npm for react?

As previously stated, Yarn installs dependency packages in parallel, whereas NPM installs them sequentially. As a result, Yarn outperforms NPM when installing bigger files. Both tools can save dependent files to the offline cache.


2 Answers

Try this :

  • Remove yarn.lock (don't need this file).
  • Remove folder node_modules
  • In package.json, change script use yarn to the same command with npm
  • Remove all global package of yarn (don't need to remove if you want to use npm for one project)
  • Remove yarn if you don't want to use it again.
  • Install npm (if you installed, ignore this step)
  • Install global and local package you need

Can you upload some error, you said that not fully work.

Edit:

If you want to change npm to yarn, it same:

  • Remove package-lock.json (don't need this file).
  • Remove folder node_modules
  • In package.json, change script uses npm to the same command with yarn
  • Remove all global package of npm (don't need to remove if you want to use yarn for one project)
  • Remove npm if you don't want to use it again.
  • Install yarn (if you installed, ignore this step)
  • Install global and local package you need

You can see CLI commands comparison for 3rd step

like image 143
hong4rc Avatar answered Oct 08 '22 07:10

hong4rc


You can try taking the following steps:

  1. Remove node_modules
  2. Run npm install

This should work because npm and yarn use the same package.json.

like image 29
iridescent Avatar answered Oct 08 '22 06:10

iridescent