【问题标题】:Error: The project seems to require yarn but it's not installed错误:该项目似乎需要纱线,但它没有安装
【发布时间】:2021-10-20 00:12:08
【问题描述】:

我有一个 Vue3 项目并使用 yarn 作为包管理器。当我尝试运行yarn serve 时,它退出并显示以下错误消息:

Yarn 是全局安装的,如果我运行 yarn --version,我会得到以下输出:1.22.11

项目编译成功。

这是我的 package.json:

{
  "name": "view",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@vue-leaflet/vue-leaflet": "^0.6.1",
    "autoprefixer": "^10.3.1",
    "core-js": "^3.6.5",
    "postcss": "^8.3.6",
    "tailwindcss": "^2.2.7",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^5.0.0-beta.3",
    "@vue/cli-plugin-eslint": "^5.0.0-beta.3",
    "@vue/cli-plugin-router": "^5.0.0-beta.3",
    "@vue/cli-service": "^5.0.0-beta.3",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.32.0",
    "eslint-plugin-prettier": "^3.3.1",
    "eslint-plugin-vue": "^7.0.0",
    "prettier": "^2.2.1",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2"
  }
}

【问题讨论】:

    标签: vue.js yarnpkg vuejs3 package.json


    【解决方案1】:

    我找到了一个与问题类似的 GitHub Issue

    修复

    它的发生是因为在 @vue/cli-shared-utils/lib/env.js 中运行了 yarnpkg 命令并且在 > solus 上只有 yarn 命令可用。硬编辑此文件以运行 yarn 命令 > 一切正常

    @vue/cli-shared-utils/lib/env.js:27

    execSync('yarn --version', { stdio: 'ignore' })

    这个改动一切正常

    但是,此修复对我不起作用。我硬编辑了@vue/cli-shared-utils/lib/env.js:19中负责检测纱线的函数,刚刚返回true:

    // env detection
    exports.hasYarn = () => {
      return true;
      if (process.env.VUE_CLI_TEST) {
        return true
      }
      if (_hasYarn != null) {
        return _hasYarn
      }
      try {
        execSync('yarn --version', { stdio: 'ignore' })
        return (_hasYarn = true)
      } catch (e) {
        return (_hasYarn = false)
      }
    }
    

    如果有人有更好的解决方案,我会接受。

    【讨论】:

      【解决方案2】:

      我偶尔会发生。
      您是否尝试过删除 node_modules/ 文件夹和 yarn.lock 文件?
      删除它们后,再次尝试安装项目:

      yarn install
      

      大部分时间它都有效,希望它对你有用;)

      【讨论】:

      • 我已经尝试了几次,但不幸的是,它对我不起作用
      猜你喜欢
      • 2022-07-06
      • 1970-01-01
      • 2018-02-11
      • 2020-04-11
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 2018-11-27
      • 2018-03-22
      相关资源
      最近更新 更多