Philip F.
Philip F.

Reputation: 1237

Error: The project seems to require yarn but it's not installed

I have a Vue3 project and use yarn as a package manager. When I try to run yarn serve, it exits with the following error message:

yarn error

Yarn is installed globally, if i run yarn --version I get the following output: 1.22.11

The project is compiled successfully.

Here is my 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"
  }
}

Upvotes: 2

Views: 13256

Answers (6)

Island_world
Island_world

Reputation: 1

if none of the above methods work,maybe since your Windows account name isn't English words,change it to a English name like 'C:\Users\abc' and fix up all relevant environment variables,especially in 'Path',npm item.


PS:if you are a Chinese developer, look up my blog in here:[Bug] Vue 项目报错:The project seems to require yarn but it's not installed

Upvotes: 0

Amir HR
Amir HR

Reputation: 1

you should install yarn in your project try this :

npm install --global yarn

the problem fixed i think

Upvotes: 0

HijeraWingFox
HijeraWingFox

Reputation: 56

I found better solution (but looks lika a hack) , just add to .env File :

VUE_CLI_TEST=true

as we can see in env.js, it checks, if process.env.VUE_CLI_TEST equals true to check that yarn exists

Upvotes: 4

Cheikh Saliou TALLA
Cheikh Saliou TALLA

Reputation: 325

To install yarn in your project, do this

npm install --global yarn

after then, do this

yarn install

Upvotes: 0

Benjamin Fourgeaud
Benjamin Fourgeaud

Reputation: 864

I happens some times.
Have you tried deleting the node_modules/ folder and the yarn.lock file ?
After deleting them, try again to install the project :

yarn install

Most of the time it works, hope it does for you ;)

Upvotes: 3

Philip F.
Philip F.

Reputation: 1237

I found a GitHub Issue which is similar to the question.

Fix

it happen because in @vue/cli-shared-utils/lib/env.js ran the yarnpkg command and on > solus only is avalible the yarn command. Hard editing this file to ran yarn command > all works fine

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

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

with this change all works fine

This fix however, did not work for me. I hard edited the function in @vue/cli-shared-utils/lib/env.js:19 which is responsible for the detection of yarn and just returned 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)
  }
}

If anyone has a better solution, I will accept it.

Upvotes: 1

Related Questions