OSX上的NPM,获取全局安装包时出错 [英] NPM on OSX, error getting global installed packages

查看:119
本文介绍了OSX上的NPM,获取全局安装包时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行OSX 10.9的MBP上安装了nodejs,我已经从nodejs网站下载了软件包.然后,按照mean.io上的说明安装了MEAN堆栈.

命令是: 须藤npm install -g mean-cli 意思是初始化yourNewApp

那正常工作

现在真正的问题是,在创建我的应用程序后,当我使用终端输入dir并编写gulp时,这让我有些错误,找不到某些必需的模块.

将模块写在package.json文件中,该文件表示已生成,并且将它们作为全局模块安装在〜/.npm上

我浏览了该文件夹,并找到了所有必需的packages文件夹,在文件夹内有一个package.tgz文件和package文件夹,其中package.tgz文件包含该软件包的代码,而package文件夹中包含一个描述软件包本身的package.json文件./p>

现在,我不明白为什么压缩了这些软件包,为什么不能全局安装它们,也无法从我的项目文件夹中的gulp进行访问.

谢谢.

解决方案

如果安装了某些global模块,则最好不要将其放入应用程序的package.json中,因为在运行应用程序时,这是第一个在要搜索的位置,如果有,则您的应用程序将查看node_modules文件夹,如果没有,则您的应用程序将崩溃.

我的建议是尝试在应用内安装模块,npm install your_module --save,因为您的应用将是可移植的,并且只需一个简单的npm install,您就可以安装所有需要的软件包.

但是,如果您仍然想安装全局软件包,则可能要遵循规则:

  1. 如果您要安装要在程序中使用的内容,请使用require('whatever'),然后在项目的根目录本地安装.
  2. 如果要在外壳程序中安装要使用的东西,在命令行上或其他东西,请全局安装它,以便其二进制文件最终位于您的PATH环境变量中.

如果您有时间阅读 解决方案

If you install some global module then you better don't put it into the package.json of your app because when you run your app that's the first place where is going to search and if it is there your app is going to look at node_modules folder and if it is not there your app will crash.

My advice is try to install your modules inside your app, npm install your_module --save because your app is gonna be portable and with a simple npm install you will be able to install all your needed packages.

But if you still wanna install global packages you maybe wanna follow this rules:

  1. If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
  2. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

If you have the time to read the link then you will see that there are exceptions and how to handle them.

这篇关于OSX上的NPM,获取全局安装包时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆