Global parameter does not work with yarn 3 - vue.js

My env:
- OS: Ubuntu 20.04
- Yarn: 3.1.1
- Node: v16.12.0
Instruction link: https://cli.vuejs.org/guide/installation.html
When I run command: yarn global add #vue/cli
I got error:
Usage Error: The 'yarn global' commands have been removed in 2.x - consider using 'yarn dlx' or a third-party plugin instead
$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

The documentation contains instructions for yarn v1.
Yarn v2 and above no longer supports the use of the global parameter.
You can view their migration guide here.
You can use yarn dlx everytime you want to run a command with vue.
Alternatively, you can install the vue cli using npm:
npm install -g #vue/cli

Yarn has removed global in v3, according to its official document.
You can use the #vue/cli the same as npx using yarn dlx without installing it globally.
yarn dlx #vue/cli do_something

Related

Can't access the vue binary in my command line

I'm have some issues when trying to install Vue CLI on my mac device.
I am using the terminal and I also want to work with yarn and not with npm.
These are the commands used:
yarn global add #vue/cli
After doing that I got a message on the terminal where it says that it has been successfully installed. However, when I try to run one of the commands:
"vue" or "vue --version"
I get the following message => zsh: command not found: vue
You should use npm instead it will work.
yarn global remove #vue/cli
and then install using npm.
npm install -g #vue/cli
don't worry! on normally you can use yarn but for global use npm.
solution - 2
yarn global bin
add yarn global directory into your path
Update, i fount the issue. So basically I was missing one extra command.
This is the chronological order for commands:
yarn global add #vue/cli
export PATH="$(yarn global bin):$PATH"
vue

I can't run vue cli in Ubuntu - Error: Unable to access jarfile /snap/vue/1/jar/vue-1.0-SNAPSHOT.jar

I am trying to install vue cli for the first time.
I tried using npm install -g #vue/cli and yarn global add #vue/cli and it seems to install correctly.
But if I run vue create my-project or vue --version, I get the following error:
Picked up _JAVA_OPTIONS: -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Error: Unable to access jarfile /snap/vue/1/jar/vue-1.0-SNAPSHOT.jar
My operative system is Ubuntu.
I had the same problem, to solve:
Remove the vue using snap
sudo snap remove vue
Then install vue globally via npm or yarn
npm install -g #vue/cli
OR
yarn global add #vue/cli
I had the same problem as mentioned but it's due to me not giving administrator privilege to the installation. Therefore, I had to give an administrator privilege to the installation by typing:
sudo npm install -g #vue/cli
Then when I need to create the Vue project I type
sudo vue create <project_name>
and it works fine.
I used these commands:
sudo snap remove vue
sudo npm install -g #vue/cli
Then created the Vue project:
sudo vue create <project_name>
let's try sudo snap remove vue you will get something like: "vue removed",
then try: vue in the terminal and see if it works ! h
This solution worked for me on my Ubuntu system:
npm:
sudo snap remove vue && npm install -g #vue/cli
Yarn:
sudo snap remove vue && yarn global add #vue/cli
Then reopen your terminal.
I fixed that using the vue-init command rather than vue init (which I've read that was the correct one). The entire command used was:
vue-init webpack-simple your-project-name
Then Vue-cli will ask you a series of questions such as project name, description and author.
Hope that helps.

How to use Create React App using Yarn 2?

In yarn v1 we initialize create react app using yarn create react-app my-app. How to initialize the same in yan v2.
The above command gives the error
Usage Error: No project found in <<directory>>
$ yarn run <scriptName> ...
Check your yarn version:
yarn --version
If it's below 1.22 you may need to upgrade it to use yarn 2:
npm install -g yarn
You can then create your app:
yarn create react-app my-app
cd my-app
yarn set version berry
yarn
yarn start
This should have your react app up and running using yarn 2. You may want to remove the node_modules folder:
rm -R node_modules
Also, you need the next line on .yarnrc.yml
nodeLinker: "node-modules"
You can use yarn dlx create-react-app my-app. It will work.
There are a lot of changes came with the yarn version2 update.
check this also for additional info: https://dev.to/arcanis/introducing-yarn-2-4eh1

NPM doesn't support PnP

I was trying use pnpm with create-react-app v2 as follows
npx create-react-app my-app --use-pnp
But it gives me following warning
NPM doesn't support PnP.
Falling back to the regular installs.
What should I do in order to use pnpm with create-react-app?
I already have pnpm installed globally using npm.
pnp is a Yarn feature, you need the latest version of yarn installed on your system to use it (at least Yarn 1.12).
Try
yarn create react-app project-name --use-pnp
And make sure yarn -v is >= 1.12

Command not found with vue-cli

While installing the dependencies of vue-cli, vue is not identified. Why?
rm -rf node_modules and npm install again
have a look here
Add sudo before yarn when installing
yarn global remove #vue/cli
sudo yarn global add #vue/cli
vue
I had the same issue for a while.
TL;DR
npm install #vue/cli-service --save-dev
As the documentation specify it is a development dependency https://cli.vuejs.org/guide/#cli-service
The CLI Service (#vue/cli-service) is a development dependency. It's an npm package installed locally into every project created by #vue/cli.
Origin
I had a fresh install of nodejs
And just did
>> sudo npm install -g #vue/cli#latest
>> vue --version
#vue/cli 4.5.8
The issue
The issue presented like this
>> npm run serve
yarn run v1.22.10
$ vue-cli-service build --mode development --watch
/bin/sh: 1: vue-cli-service: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The fixes:
npm install #vue/cli-service --save-dev
Which led me straight to another error message
>> npm run serve
yarn run v1.22.10
$ vue-cli-service build --mode development --watch
ERROR Error: Cannot find module 'vue-template-compiler/package.json'
Which I fixed the same way
npm i vue-template-compiler --save-dev
And now it is working fine.
Installing current version without permanently installing vue-cli.
npx #vue/cli create appname
It shows the vue executable is located at /home/alisha/.local/bin. So probably this location is not there in your $PATH.
You should be able to run the vue commands if you provide the full path, like:
~/.local/bin/vue create hello-world
You can also see if that directory is in your PATH by running some command like:
echo $PATH | grep '.local/bin/'
If it's there, you would see it, otherwise you can add it to your path by placing it in your ~/.profile.
Edit ~/.profile and add the following at the bottom of it.
PATH="$HOME/.local/bin:$PATH"
Hope it helps!!
I had the same issue while making a build for production.
You will require vue-cli to be installed. Use below command to install the latest version.
npm install -g #vue/cli#latest
Then
npm install
Might have to do with you having an old version on your computer:
Warning regarding Previous Versions
The package name changed from vue-cli to #vue/cli. If you have the previous vue-cli (1.x or 2.x) package installed globally, you need to uninstall it first with
npm uninstall vue-cli -g or yarn global remove vue-cli.
You can find it here: https://cli.vuejs.org/guide/installation.html
THIS FIXED THE ISSUE FOR ME:
After running
sudo npm install -g #vue/cli
I ran
sudo nano $HOME/.profile
and pasted the following line
export PATH=$PATH:/home/chike/.npm-global/bin
after writing the code, next thing I did was Ctrl + O, ENTER and Ctrl + X then wrote
vue init webpack myapp
When you install vue using cli that time you got the path of vue.Now you can copy the bin folder path.
In my example /home/sublime/.npm-packages/bin
Now you export the path below command
export PATH=$PATH:/home/sublime/.npm-packages/bin
I solved mine by running (add sudo if needed)
npm i -g vue-cli#2.9.6
npm i -g #vue/cli
Got similar issue when deploy vue project in jenkins.
Here is what I did:
Add node's bin/ dir, to jenkins user's .bashrc file.
e.g
# node
NODE_HOME=/home/dev/.nvm/versions/node/default
PATH=$NODE_HOME/bin:$PATH
Tips - about nvm & yarn
When you manage node version via nvm, make sure you already choose the node version in terminal. e.g:
nvm use stable
node -v
If you use nvm, and installed yarn via npm, then better install vue-cli via npm not yarn, otherwise the vue executable is not placed into node's bin/ dir, at least that's the case in my tests, and as a result will cause you fail to find the vue command.
Using Yarn on Ubuntu it is installed to ~/.npm-packages/bin/. You must add this directory to your PATH. For example run the following command, close your terminal and open a new one.
user#machine:~$ echo 'export PATH="$PATH:~/.npm-packages/bin/"' >> ~/.bashrc
Note: if the file ~/.bashrc does not exist then simply create it.
Following worked for me:
First remove all the existing ones:
yarn global remove #vue/cli
yarn global remove #vue/cli-service
sudo yarn global remove #vue/cli
sudo yarn global remove #vue/cli-service
Then add #vue/cli using sudo:
Note: use sudo if required
yarn global add #vue/cli
yarn global add #vue/cli-service
Then, the final thing to do is to RESTART the terminal.
vue --version
#vue/cli 4.5.9
If you already got a project, the only two things you need to do is:
Delete the directory node_modules (it is safe, since it is not under git and will regenerate in the next step)
In the command-line write yarn install (it will install everything you need)
If you start installing vue-cli manually in a existing project, it the package.json and package-lock.json will be updated. If you already did. Do a checkout from git, and follow my steps above
This may be a problem caused by version conflicts. "export PATH=$PATH:" This is really useful in some cases. But if you are also like me, after trying the direct “export path” method in the comment above, restarting the terminal still can not execute the situation, you can try this way.
Uninstall Vue
npm uninstall -g #vue/cli
Check the local-global npm package installation path, vue is installed in this directory, check if it has been removed.
npm root -g
Install vue (you can check with https://cli.vuejs.org/#getting-started to find the latest command)
npm install -g #vue/cli
Create a connection to the /usr/local/bin directory(You need to find the vue.js path after the local installation first, then replace this path with your latest local install path:/Users/xxxxx/.npm-global/lib/node_modules/#vue/cli/bin/vue.js)
ln -s /Users/xxxxx/.npm-global/lib/node_modules/#vue/cli/bin/vue.js /usr/local/bin/vue
View version number
vue -v
I was getting the same error because Node.js was not installed. My issue got resolved by installing Node.js using the following command:
sudo apt install nodejs-legacy
To see if you already have Node.js and npm installed and check the installed version, run the following commands:
node -v
npm -v
If both are installed then follow the steps here:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
I installed the package using yarn global add #vue/cli on my Ubuntu box and found the binary in /home/vonkad/.yarn/bin.
I had to modify my /home/vonkad/.bashrc and add the directory to the path export PATH=$PATH:/home/vonkad/.yarn/bin.
To fix this situation, I had to add the following line to my .zshrc (maybe in your case is .bashrc)
export PATH="$(yarn global bin):$PATH"
Effectively, the yarn global bin is a folder where vue (vue-cli 3) was placed.
What helped me
mac os catalina with zsh terminal
Uninstalled node and npm using https://www.positronx.io/how-to-uninstall-node-js-and-npm-from-macos/
Downloaded node/npm from https://nodejs.org/en/download/current/
sudo npm install -g #vue/cli
vue --version (#vue/cli 4.5.4)
I faced the same issue and now resolved. In my case I installed Node.js and NPM using the default Ubuntu repository by using this command sudo apt-get install nodejs npm
The problems seemed like those 2 packages are not well maintained so it caused some bugs.
So I purge those packages and reinstall it from nodesource which is officially recommended way to install (reference: Installation instruction from nodesource) using these commands.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then reinstall #vue/cli again
sudo npm install -g #vue/cli
Now these issues have gone. Hope it helps some programmers.
You need to install vue via sudo like explained in the doc:
https://cli.vuejs.org/guide/installation.html
If you have WSL2 running and you use zsh like me, just add
yarn global add #vue/cli
# add this line to ~/.zshrc
export PATH="$HOME/.yarn/bin:$PATH"
$ vue --version
#vue/cli 4.x.xx
You can try the following code install see
npm install --global vue-cli
vue init webpack <YOUR-PROJECT-NAME-HERE>
cd <YOUR-PROJECT-NAME-HERE>
npm install
npm run dev