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 :)
  • 相关阅读:
    LeetCode题解之Flipping an Image
    LeetCode 之Find Minimum in Rotated Sorted Array
    LeetCode题解Transpose Matrix
    LeetCode 题解之Minimum Index Sum of Two Lists
    LeetCode题解之Intersection of Two Linked Lists
    LeetCode 题解之Add Two Numbers II
    LeetCode题解之Add two numbers
    href="#"与href="javascript:void(0)"的区别
    有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除
    ie7下属性书写不规范造成的easyui 弹窗布局紊乱
  • 原文地址:https://www.cnblogs.com/xingxia/p/web_npm.html
Copyright © 2011-2022 走看看