npm之基本使用

摘要:
1.以管理员模式打开cmd清除你的npm缓存:npmcacheclean-f2.清除完缓存后,安装最新版本的Nodehelper:npminstall-gn如果发生错误执行:npminstall-gn--force2.NoXcodeorCLTversiondetected!

基本命令

1.初始化项目(生成package.json)

npm init

2.添加依赖

npm install(i) [package]@[version] (-S/-D) (-g)

参数解析:

1.install(i)  install有一个简写i
2.[package]@[version] package为npm包名,后面的@[version]可选,没有的时候默认安装最新版本
3.-S/-D,-S是--save的简写,-D是--save-dev的简写,-S与-D的区别就是-S会被打包到运行环境中去,-D只是在开发中使用,比如babel转码
4.-g是-global的简写,这个选项会被npm包安装到全局去,一般用于一些在命令行使用的npm包,比如vue-cli,使用-g时没有-S/-D选项

3.删除依赖

npm uninstall (-g) [package]

4.更新依赖

npm update (-g) [package]
查看过期包 npm outdated [package]
查看包版本 npm ls [package]

5.运行脚本

npm run [scriptname]
常见的有vue-cli中的npm run dev、npm run build

6)查看镜像源

npm config getregistry

设置镜像源:
npm config set registry https://registry.npm.taobao.org
或者直接查看文件:
 .npmrc

常见问题:

1.npm ERR! cb()never called!

1.以管理员模式打开cmd清除你的npm缓存 : npm cache clean -f

2.清除完缓存后,安装最新版本的Node helper: npm install -g n 

如果发生错误执行:npm install -g n --force

2.No Xcode or CLT version detected!

解决:

Mac升级到High sierra 后,发现执行使用npm 或者yarn 的时候,不时会报gyp: No Xcode or CLT version detected!的错误, 原因是缺了xcode 的CLI 工具, 只要执行下面的命令来安装就可以了

   sudo xcode-select --install
再执行:
     $ xcode-select --install

出现错误: xcode-select: error: command line tools are already installed, use "Software Update"to install updates


解决:
$ sudo rm -rf /Library/Developer/CommandLineTools
 $ sudo xcode-select --install

3.code for hash md5 was not found

The case for me isthat when I install dependencies of a django web app, it messes up the environment. When I type cd, it shows the same error.

The problem was the openssl library, it can not find the correct ones.

If you are on Macintosh, you can type


ls /usr/local/Cellar/openssl


to see all the versions,


brew switch openssl 1.0.XXXX


to choose the available openssl version.

Then the error is gone :)

免责声明:文章转载自《npm之基本使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇c# string.format 中使用$的坑Java ActiveMQ 讲解(二)Spring ActiveMQ整合+注解消息监听下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

CentOS 6安装Oracle 11gR2数据库

1.安装环境--- 操作系统:CentOS release 6.8 (Final) oracle:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 【1】安装依赖包: yum -y install binutils compat-libcap1 co...

Nginx简介及环境搭建

什么是Nginx? Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5万并发链接,并且cpu、内存等资源消耗却非常低,运行非常稳定。本文主要简述Nginx的环境搭建步骤和注意事项,仅供学习分享使用,如有不足之处,还请指正。 Ng...

linux系统redhat 8.3 安装R

1、查看当前系统: [root@rhel8 home]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.3 (Ootpa) [root@rhel8 home]# hostnamectl Static hostname: rhel8 Icon name: comp...

Composer依赖管理 – PHP的利器

别再到处搜PHP类扩展包了,对于现代语言而言,包管理器基本上是标配。Java 有 Maven,Python 有 pip,Ruby 有 gem,Nodejs 有 npm。PHP 的则是 PEAR,不过 PEAR 坑不少: 依赖处理容易出问题 配置非常复杂 难用的命令行接口 好在我们有 Composer,PHP依赖管理的利器。它是开源的,使用起来也很简...

Linux(ubuntu)安装MediaWiki

本篇文档所述步骤,作者完全验证过。一切OK。 作者:http://gaoxingf.blog.51cto.com/612518/188132,Younger Liu 本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 未本地化版本许可协议进行许可。 1. 编译安装libxml2 #wget ftp://xmlsoft.org/libxml2/lib...

npm install -g create-react-app MacOS 报错解决

macOS 安装create-react-app报错解决: sudo npm uninstall -g create-react-app //删除之前对镜像 npm config set registry https://registry.npm.taobao.org // 安装还是不成功直接切换成淘宝镜像安装 npm config get regist...