简体   繁体   English

出现依赖项错误时,恢复为Package.json的先前版本

[英]Reverting to Previous Version of Package.json When a Dependency Bug Arises

While in the process of updating an Angular app I and colleagues are working on, I ended up running "npm update" when I meant to run "npm install". 在我和同事正在开发Angular应用程序的过程中,当我打算运行“ npm install”时,我最终运行了“ npm update”。 Doing so led me on a bit of a rabbit trail because of course now all my dependencies - AND their dependencies got updated in the process. 这样做使我走上了一条小路,因为现在我的所有依赖项都已经有了,而且它们的依赖项在此过程中得到了更新。 From there I had to resolve certain conflicts to get the new versions to work correctly. 从那以后,我必须解决某些冲突才能使新版本正常工作。 However, this also led me to a point where a bug in one of those dependencies is preventing my app from booting up. 但是,这也导致我陷入一个依赖点,即其中一个依赖项中的错误阻止了我的应用程序启动。 According to the the Angular github repo, the issue is being worked on. 根据Angular github存储库,此问题正在处理中。

My question is, how can I revert to my previous setup in the meantime? 我的问题是,如何同时恢复到以前的设置? I tried copy and pasting the package.json file as it originally existed before my "npm update", deleting my "node modules" folder, and running "npm install" again. 我尝试复制并粘贴package.json文件,因为它原来在“ npm更新”之前就存在,删除了“节点模块”文件夹,然后再次运行“ npm install”。 But this doesn't resolve the issue. 但这不能解决问题。 Is there a way I can be assured of reverting to my previous working setup? 有什么办法可以确保我恢复到以前的工作设置吗?

The process you described should work: 您描述的过程应该可以工作:

  • Get an old copy of your package.json from your repository at the state you know it worked 从存储库中以您知道其工作状态的状态获取package.json的旧副本
  • Run rm -rf node_modules to remove the node_modules folder 运行rm -rf node_modules删除node_modules文件夹
  • Run npm install to install again 运行npm install重新安装

If that didn't work, verify that you: 如果那不起作用,请验证您:

  • are in the correct directory (that should contain package.json and node_modules ) 位于正确的目录中(应包含package.jsonnode_modules
  • have permissions to clean the node_modules folder ( chmod 777 node_modules ) 有权清理node_modules文件夹( chmod 777 node_modules
  • the package.json that is written in the file system is actually the restored one (sometimes an IDE or Git can create a weird shadow copy where you think it's one way, but it's really another). 写在文件系统中的package.json实际上是已还原的文件(有时,IDE或Git可以创建怪异的卷影副本,您认为这是一种方式,但实际上是另一种方式)。 You can tell this by using cat package.json and inspecting the output 您可以使用cat package.json并检查输出来告诉我们

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

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