Yarn Type Error: "Invalid Number of Spaces" - npm

I have a work project that is configured using yarn. I've used npm commands on other projects for the company, but for this project, I need to use yarn. The reason that I haven't used yarn before is because whenever I run any yarn commands locally, I get the following error:
TypeError: Invalid number of spaces
at tokenise (/usr/local/lib/node_modules/yarn/lib/cli.js:63358:17)
at tokenise.next (<anonymous>)
I'm on a mac and have tried running yarn, brew install yarn,npm install --global yarn and curl --compressed -o- -L https://yarnpkg.com/install.sh | bash. I've also tried npm uninstall yarnand brew uninstall yarn to try to start fresh, but after each attempt at removing and reinstalling, I get the same error.
The cloned repository that I'm working with includes a .yarnrc file and a yarn.lock file. Also, I'm on a work vpn, and have to install dependencies over the vpn, so I have a mirror registry in my .yarnrc file.
Any suggestions on where to start troubleshooting? Obviously, I'm doing something wrong here.

Related

I can't run ganache in my terminal, even though it's installed

It seems I have a path error, I can see proof the package installed, and I've tried it both globally and local, tried both with and w/o the -cli suffix, but zshell keeps complaining command not found
dr_frankenmiller#Bryans-MacBook-Pro ~ % npm install ganache-cli
npm WARN deprecated ganache-cli#6.12.2: ganache-cli is now ganache; visit https://trfl.io/g7 for details
added 1 package, and audited 102 packages in 11s
2 packages are looking for funding
run npm fund for details
9 vulnerabilities (8 moderate, 1 high)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run npm audit for details.
dr_frankenmiller#Bryans-MacBook-Pro ~ % npm ls --depth=0
dr_frankenmiller# /Users/dr_frankenmiller
└── ganache-cli#6.12.2
dr_frankenmiller#Bryans-MacBook-Pro ~ % ganache-cli
zsh: command not found: ganache-cli
I might have done something bad, using a sudo rm -rf node_modules command to uninstall the package, was that dangerous to do? I reinstalled it globally and then tried running it again, and then zshell started complaining I wasn't authorized to run ganache. I tried the command sudo ganache, it asked me for password, and then responded again that command not found.
Can someone help me get back on track with my tutorial?
According to Ganache-CLI's instructions, it should be installed with:
npm install ganache-cli -g
I'd recommend installing the latest Ganache version rather than installing Ganache-CLI, though. Ganache-CLI is deprecated. Use
npm uninstall ganache-cli && npm install ganache -g
Ganache v7.0.0 and onward can be used in the CLI as well as programatically.
On another note, I strongly recommend against using sudo when installing anything via npm. This can give untrusted code the ability to run as admin on your system. Definitely a big security risk.
Just a follow up on difficulties I was having, I ended up using yarn to download and run ganache (MINUS the -cli suffix, -cli suffix now deprecated), yarn install ganache --global to install and then yarn ganache to run (no -cli necessary)
Here's how I found the solution for my specific use case. The bug came about when I was attempting to run a brownie deployment script. Run npm uninstall ganache-cli then run yarn global add ganache. Worked like a charm.

NPM insists on using the wrong registry URL

Using NPM to install dependencies, including one that is stored in Verdaccio running locally.
Somehow NPM is stuck attempting to load the Verdaccio dependency from localhost even though the command to install from the corrected location has been run npm install --save --registry http://CORRECT-URL ...
Using rm -rf node_modules package-lock.json and removing the dependency from package.json, then running the install again - still DOES NOT WORK. Every time the install command completes, package-lock.json STILL uses localhost to resolve the registry.
Removing localhost from ~/.npmrc and running npm set registry http://CORRECT-URL also didn't help.
Please help. Where is NPM remembering localhost and insisting on using it???
UPDATE - Using npm install -ddd
Attempted to use npm install -ddd to see where npm is picking up the package. The output shows the CORRECT-URL, but when it is done, package-lock.json still lists localhost.
Note all of the following:
Removed all references to the PACKAGE from package.json and package-lock.json
Verified no references to localhost in either file
Removed node_modules/PACKAGE_DIR with rm -rf
Removed PACKAGE from node_modules/.package-lock.json
Searched for .npmrc and npmrc in the build tree and found two empty files:
node/node_modules/npm/docs/public/configuring-npm/npmrc
node/node_modules/npm/.npmrc
~/.npmrc has 2 entries for the CORRECT_URL in the following forms:
//:/:_authToken="<AUTH_TOKEN>"
registry=http://:/
Stumbled upon this post while trying to debug the exact same situation. What ended up solving this for me was to blow out package-lock, run npm rebuild, then npm install --registry . Hope this helps someone in the future!

All of sudden gulp command not recognizing in spfx solution

Solution type: SharePoint SPFx
I made windows update on this Sunday. From that point, I am not able to execute gulp commands. I am not sure if there is any relation between windows update and gulp command. I am getting below error.
I have installed gulp again by npm install gulp -g. I have restarted my machine and tried. But still same issue. I have added this in environment variables also.
I have followed all the instructions explained in this issue but no resolution found.
After installation of gulp globally when I run below command it is not list me gulp
You are checking the local packages, but you should check the global:
npm list -g --depth=0

Cannot Find Module

I am trying to run react-native start and the following error appears
"Cannot find module 'metro-core'. Run CLI with --verbose flag for more details.
Prior to getting this message, I had a different error message saying modules was not located, so I tried this:
Delete the node_modules folder -
rm -rf node_modules && npm install
Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache
Clear watchman watches - watchman watch-del-all
I just typed in the react-native start and the error message popped up on the simulator, which told me to look at my terminal for the error message.
This is common with NPM. Do not worry. Just follow a few steps and you will get your package.
Step 1: $ npm cache clean --force
Step 2: delete node_modules by $ rm -rf node_modules folder or delete it manually by going into the directory and right-click > delete.
Step 3: npm install
To start again, $ npm start
This worked for me. Hopes it works for you too.
Still, if it is there, kindly checks the error it displays in red and acts accordingly.
Be careful when using rm -rf.
After that,
While working on Unix systems.
Sometimes it may not allow you to install such packages. For that, you need sudo permissions.
Sometimes, the package is installed but only in your local modules, and when you try to import(require) it from outside of the directory, the error occurs.
Sometimes, your compiler read your dependencies, but not able to find this package in that, at that time also you face this error.
Anyways, don't worry. You just have to follow some steps below.
A best practice is to initialize your project using npm init before starting development. This will initialize your project and generate package.json file. (Ignore it if your project have package.json file)
Then, if you want any library as dependencies, try --save with npm install command. This will save your dependency in package.json file.
e.g. npm install metro-core --save
If any package is not found after installing, install it globally by -g flag.
Globally installed packages will be accessible within your system. e.g. npm install metro-core -g.
Note: Unix system needs SUDO permission for installing it globally.
I hope this will help you.
npm install metro-core
use command then run

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