react-native: switch from yarn to npm

冷暖自知 提交于 2020-01-01 08:46:06

问题


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?


回答1:


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 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 change npm to yarn, it same:

  • Remove package-lock.json (don't need this file).
  • Remove folder node_modules
  • In package.json, change script use npm to the same command with yarn
  • Remove all global package of npm (don't need 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




回答2:


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.




回答3:


The deyarn package worked brilliantly for me.

Note that it will only flag (not auto-update) any package-lock.json scripts that you may need to update.

Depending on your environment needs, you may also want to strip out the engines: yarn: '..' entry it adds to your package-lock.json.



来源:https://stackoverflow.com/questions/51239726/react-native-switch-from-yarn-to-npm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!