Vue.js一些问题解决

我在使用npm安装项目依赖时经常会卡住或者是安装失败所以使用了yarn

npm和yarn

npm的缺点:
  1. 速度较慢:在安装依赖和执行脚本时,npm的速度相对较慢,特别是在大型项目中。

  2. 安装过程不稳定:有时候npm的安装过程可能会出现问题,例如网络问题或者依赖版本冲突等。

  3. 锁文件不稳定:npm的package-lock.json文件在一些情况下可能会导致依赖版本的不一致性。

与npm相比,Yarn具有以下优势:
  1. 更快的安装速度:Yarn使用并行和缓存机制,因此通常比npm快。

  2. 确保依赖一致性:Yarn使用yarn.lock文件来确保依赖的一致性,避免了npm中出现的版本冲突问题。

  3. 更好的网络支持:Yarn的网络请求稳定性更好,能够更好地处理网络环境不佳的情况。

  4. 更好的用户体验:Yarn提供了更清晰、更易用的命令行界面,并且在输出信息方面更加友好。

总的来说,Yarn在速度、一致性和用户体验方面都优于npm。但是,npm作为Node.js的默认包管理器,在生态系统和社区支持方面具有优势。选择使用哪个取决于您的具体需求和偏好。如果您注重速度和一致性,那么Yarn可能更适合您;如果您更看重广泛的社区支持和生态系统,那么npm可能是更好的选择。

以下是Yarn的安装:
  • Yarn中文文档安装官网:安装 | Yarn 中文文档

  • 进入命令提示符窗口输入:npm install --global yarn

    C:\Users\Administrator>npm install --global yarn
    
    changed 1 package, and audited 2 packages in 5s
    
    found 0 vulnerabilities
  • ,检查是否安装成功可以使用:yarn --version
    C:\Users\Administrator>yarn --version
    1.22.21
    

Yarn和npm在使用上有一些区别,包括以下几个方面:
  1. 初始化项目:
  • 使用npm:在命令行中,使用npm init命令初始化一个新的npm项目,然后按照提示输入项目信息。
  • 使用Yarn:在命令行中,使用yarn init命令初始化一个新的Yarn项目,然后按照提示输入项目信息。
  1. 安装依赖:
  • 使用npm:在命令行中,使用npm install <package>命令安装npm包,可以使用--save参数将依赖项添加到package.jsondependencies字段中,或者使用--save-dev参数将其添加到devDependencies字段中。
  • 使用Yarn:在命令行中,使用yarn add <package>命令安装Yarn包,可以使用--save参数将依赖项添加到package.jsondependencies字段中,或者使用--dev参数将其添加到devDependencies字段中。
  1. 更新依赖:
  • 使用npm:在命令行中,使用npm update <package>命令更新指定的npm包。
  • 使用Yarn:在命令行中,使用yarn upgrade <package>命令更新指定的Yarn包。
  1. 删除依赖:
  • 使用npm:在命令行中,使用npm uninstall <package>命令从项目中删除指定的npm包。
  • 使用Yarn:在命令行中,使用yarn remove <package>命令从项目中删除指定的Yarn包。
  1. 安装项目依赖:
  • 使用npm:在命令行中,使用npm install命令安装项目中的所有依赖项。
  • 使用Yarn:在命令行中,使用yarn命令安装项目中的所有依赖项。
除了上述区别,Yarn还有一些特有的命令和功能,例如yarn upgrade-interactive命令用于交互式地更新依赖项,以及yarn workspaces功能用于管理多个相关项目。这些特性使得Yarn在某些方面更加强大和灵活。

这是一个在安装项目依赖时产生的保持信息

tough-cookie  <4.1.3
Severity: moderate
tough-cookie Prototype Pollution vulnerability - https://github.com/advisories/GHSA-72xf-g2v4-qvf3
fix available via `npm audit fix --force`
Will install @vue/cli-plugin-babel@5.0.8, which is a breaking change
node_modules/tough-cookie
  request  *
  Depends on vulnerable versions of tough-cookie
  node_modules/request
    @vue/cli-shared-utils  <=4.5.19
    Depends on vulnerable versions of request
    node_modules/@vue/cli-shared-utils
      @vue/cli-plugin-babel  3.4.0 - 4.5.19
      Depends on vulnerable versions of @vue/cli-service
      Depends on vulnerable versions of @vue/cli-shared-utils
      node_modules/@vue/cli-plugin-babel
      @vue/cli-plugin-router  <=4.5.19
      Depends on vulnerable versions of @vue/cli-shared-utils
      node_modules/@vue/cli-plugin-router
        @vue/cli-service  *
        Depends on vulnerable versions of @vue/cli-plugin-router
        Depends on vulnerable versions of @vue/component-compiler-utils
        Depends on vulnerable versions of copy-webpack-plugin
        Depends on vulnerable versions of css-loader
        Depends on vulnerable versions of cssnano
        Depends on vulnerable versions of html-webpack-plugin
        node_modules/@vue/cli-service
          @vue/cli-plugin-vuex  <=4.5.19
          Depends on vulnerable versions of @vue/cli-service
          node_modules/@vue/cli-plugin-vuex

71 vulnerabilities (1 low, 49 moderate, 14 high, 7 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

根据提供的信息,tough-cookie 版本存在一个中等级别的原型污染漏洞。npm 提供了解决这个漏洞的建议,可以使用 npm audit fix --force 命令来尝试修复它。但请注意,这可能会引入一个破坏性的变化,因为它将安装 @vue/cli-plugin-babel@5.0.8,这是一个重大改变。

此外,还有其他的漏洞问题,总共有 71 个漏洞(其中包括 1 个低级别、49 个中等级别、14 个高级别和 7 个严重级别)。可以通过运行 npm audit fix 命令来解决不需要特别关注的问题。

在进行任何更改之前,强烈建议备份你的代码。请记住,修复漏洞是保证项目安全性的重要步骤。

最终是使用 npm audit fix --force 命令来修复它

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值