zoukankan      html  css  js  c++  java
  • npm之基本使用

      

    基本命令

      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 get registry
    
    设置镜像源:
    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 is that 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 :)
  • 相关阅读:
    浅谈Dynamic 关键字系列之三(下):ExpandoObject,DynamicObject,DynamicMetaObject
    完全详解Silverlight 下载文件
    在内部循环中Continue外部循环
    浅谈Dynamic 关键字系列之四:dynamic为什么比反射快
    Android学习笔记(三)基础知识(2)
    Android学习笔记(一) 使用选择部件
    Android学习笔记(四)时钟、时间
    每周一道数据结构(三)树、二叉树、最优二叉树
    Linux内核设计与实现笔记(二) 内存管理、进程地址空间
    Windows下Hadoop eclipse开发平台搭建
  • 原文地址:https://www.cnblogs.com/xingxia/p/web_npm.html
Copyright © 2011-2022 走看看