简体   繁体   English

react-native:从纱线切换到 npm

[英]react-native: switch from yarn to npm

Is there a step-by-step process to change a react-native project from using yarn as the package manager to using npm?是否有将 react-native 项目从使用 yarn 作为包管理器更改为使用 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.经过几天的搜索,我只能找到从 npm 到 yarn 的说明以及一个名为deyarn的包,它似乎并不完全适合我。 Does anyone have a good resource on this?有没有人有这方面的好资源?

Try this :尝试这个 :

  • Remove yarn.lock (don't need this file).删除yarn.lock (不需要这个文件)。
  • Remove folder node_modules删除文件夹node_modules
  • In package.json , change script use yarn to the same command with npmpackage.json ,将脚本 use yarn 更改为与npm相同的命令
  • Remove all global package of yarn (don't need to remove if you want to use npm for one project)删除所有全局的yarn包(如果你想在一个项目中使用npm不需要删除)
  • Remove yarn if you don't want to use it again.如果您不想再次使用yarn请将其取下。
  • Install npm (if you installed, ignore this step)安装npm (如果你安装了,忽略这一步)
  • Install global and local package you need安装你需要的全局和本地包

Can you upload some error , you said that not fully work .你能不能上传一些error ,你not fully work

Edit:编辑:

If you want to change npm to yarn , it same:如果要将npm更改为yarn ,则相同:

  • Remove package-lock.json (don't need this file).删除package-lock.json (不需要这个文件)。
  • Remove folder node_modules删除文件夹node_modules
  • In package.json , change script uses npm to the same command with yarnpackage.json ,更改脚本使用npmyarn相同的命令
  • Remove all global package of npm (don't need to remove if you want to use yarn for one project)删除所有npm全局包(如果你想在一个项目中使用yarn不需要删除)
  • Remove npm if you don't want to use it again.如果不想再次使用,请删除npm
  • Install yarn (if you installed, ignore this step)安装yarn (如果你安装了,忽略这一步)
  • Install global and local package you need安装你需要的全局和本地包

You can see CLI commands comparison for 3rd step您可以看到第三步的CLI 命令比较

You can try taking the following steps:您可以尝试采取以下步骤:

  1. Remove node_modules删除node_modules
  2. Run npm install运行npm install

This should work because npm and yarn use the same package.json.这应该有效,因为 npm 和 yarn 使用相同的 package.json。

The deyarn package worked brilliantly for me. deyarn包对我来说效果很好。

Note that it will only flag (not auto-update) any package-lock.json scripts that you may need to update.请注意,它只会标记(而不是自动更新)您可能需要更新的任何 package-lock.json 脚本。

Depending on your environment needs, you may also want to strip out the engines: yarn: '..' entry it adds to your package-lock.json.根据您的环境需要,您可能还想去掉engines: yarn: '..'条目,它添加到您的 package-lock.json 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM