简体   繁体   English

在没有--save标志的情况下全局安装npm软件包仍然存在package.json或等效文件

[英]installing npm packages globally without --save flag is there still a package.json or equivalent

I am on OS X, I intend on upgrading my mac in the respectively near future and I am curious to know if there is a package.json or equal component to npm available to me for packages I have installed over time. 我在OS X上,打算在不久的将来分别升级我的mac,我很好奇我是否知道随着时间的推移我已经安装了package.json或npm的等效组件。 That I can make sure I transfer over to a new machine when that time comes that makes re-obtaining some of these easier as I've personally forgotten many of the packages I have installed over time. 我可以确保在那个时候到来时转移到新机器上,这使得重新获取其中的一些变得容易,因为我个人已经忘记了我随时间推移安装的许多软件包。

Also future proofing my problem is there any good practices for managing dependencies of ones day to day life that would making moving to a new computer or working on multiple computers easier 同样,将来可以证明我的问题是,有任何良好的做法可以管理日常生活中的依存关系,从而使移至新计算机或在多台计算机上工作变得更加容易

npm ls -g --depth=0

This command lists all your globally installed packages. 此命令列出了所有全局安装的软件包。

Using some unix utilities, we can convert the output of this command into a string that npm install can work with. 使用一些Unix实用程序,我们可以将该命令的输出转换为npm install可以使用的字符串。

npm ls -g --depth=0 | sed '1d' | cut -c5- | tr '\n' ' '

This command gives you a space separated string of every global package you have installed, with exact version numbers. 此命令为您提供了已安装的每个全局软件包的空格分隔字符串,并带有确切的版本号。 You can simply copy paste this string and run npm install -g with it on your new computer. 您可以简单地复制粘贴此字符串,然后在新计算机上运行npm install -g

This works for me on npm 3.5.3 . 这对我适用于npm 3.5.3 The output of the npm ls command might be different based on version number so it's possible this won't work for you. 根据版本号, npm ls命令的输出可能会有所不同,因此这可能对您不起作用。 If so, either adjust the pipeline or try installing my version of npm (won't affect your other packages). 如果是这样,请调整管道或尝试安装我的npm版本(不会影响您的其他软件包)。

I'm not not aware of easier methods to transfer global packages between computers. 我不知道在计算机之间传输全局软件包的简便方法。 When you install packages without --save, it simply downloads the folder to your global packages location. 如果不使用--save安装软件包,则只​​需将该文件夹下载到全局软件包位置即可。
By design , installing packages globally with package.json is out of the question as well. 通过设计 ,也不可能在package.json中全局安装软件包。

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

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