Errors using yarn Package Manager - javascript

I have been using npm to install packages using sudo before each command. Considering that this is a bad practice, I have installed yarn in order to manage my packages. After installing yarn and running a package installation, I am obtaining the following errors:
info No lockfile found.
Should I manually create this file, or yarn should be creating one on its own?
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
If I clear the package-lock.json file, then npm will no longer find the packages. Do I need to uninstall all the packages that were initially installed using npm, and re-install everything if I wish to exclusively use yarn in the future? There are quite a few packages.
error An unexpected error occurred: "EACCES: permission denied, mkdir '/home/username/node_modules/cacheable-request'".
I suppose that this error is due to the fact that I had initially installed nodes with sudo permission. How can I fix this permission issue?

Assuming you are using Linux (because of the sudo command).
info No lockfile found.
The first time yarn successfully installs dependencies it create the file.
warning package-lock.json found
Just a Warning is not recommended to use both yarn and NPM but is not a problem.
error An unexpected error occurred: "EACCES: permission denied
You should be the owner of /home/<you_username>/node_modules to check this run this command ls -l ~/node_modules if the owner is the root (because of use sudo npm) you can change to you again running sudo chown -R $USER ~/node_modules
Then you should be able to run yarn again to install all your dependencies.

Related

ENOLOCK npm ERR! Error while running npm audit fix

I am trying to install GLOBALLY a package with npm from my home directory. After the install has completed, it indicates vulnerabilities. Upon trying to run npm audit fix, I obtain the following error.
npm ERR! code ENOLOCK npm ERR! audit This command requires an existing
lockfile. npm ERR! audit Try creating one first with: npm i
--package-lock-only npm ERR! audit Original error: loadVirtual requires existing shrinkwrap file
I understand that the error asks me to run npm i --package-lock-only, but in which directory should I be creating this file? Running the command without specifying a path does not work. I have also tried to create the file in the directory where the package was installed, but that has also not solved the issue. Also, why isn't this file present to start with?
npm audit fix is intended to fix vulnerabilities with the dependencies of your own project. Projects do have a package-lock.json file.
It is not intended for globally installed packages. If there are vulnerabilities with packages from others, they need to be fixed by the package maintainer in a new release. You can then update to this new release.
BTW, you should not use globally installed packages. Use npx instead.

Gatsby CLI Won't Install

I'm trying to install the Gatsby CLI, but I run into this error every time.
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
I'm on a Mac, and I am using the sudo command. sudo npm install -g gatsby-cli is what's getting me here. Since I'm using sudo, I don't understand why there's a permissions problem.
Any recommendations?
Thanks a lot!

Yarn install: "Not a git repository" error when fetching packages

System: Windows 10 64 bit
I am trying to build a JavaScript project using yarn install --lock-file in the repository directory. When yarn tries to fetch the packages, it fails with the following error message:
Exit code: 128
Command: git
Arguments: pull
Directory: C:\Users\[UserDirectory]\AppData\Local\Yarn\Cache\v2.tmp\9f5ed3b3940e461693021bf6d9a7805d
Output:
fatal: not a git repository (or any of the parent directories): .git
I cannot figure out why yarn is trying to use git pull in another directory. Can you explain me what yarn is doing here?
Edit:
At first, I guessed it must be an issue with access rights, but running it with elevated access gave the same result. The same goes for yarn install, so without the --frozen-lockfile flag.
I was getting the same error in a repo of mine too for any yarn command.
Removing the Yarn Cache fixed yarn for me:
rm -rf C:\Users\<user>\AppData\Local\Yarn\Cache\v2.tmp\<hash>
Edit: Safer to run yarn cache clean instead.

npm installation in command prompt

After setting new windows in my laptop,i am trying to install npm in command prompt.But i am facing an error which picture is given in below.Would anybody help me out?
If you don't specify a package to install (like npm install -g nodemon) npm will try to install all packages from the current package.json file. If there is non, npm will throw this error.
Npm is already installed. That is why the error message is not Command not found.
The specific command you issued npm install -g attempts to use npm to install the package in the current directory globally.
Leaving the point that installing packages globally is a bad idea aside, this is failing because you are running the command in a directory that does not contain a package. It is your home directory, not one containing a package.json file.
If you are trying to install npm(node package manager) do it by downloading it from here: https://www.npmjs.com/get-npm, then you are good to go.
The command you are actually giving is to install a package using npm(check https://docs.npmjs.com/cli/install).
Thats why the error shows could not install from "" as you have not specified any package to install.

Visual Studio Code Error - Failed to load jshint library

Every time Visual Studio Code started or loaded it shows an error message:
"Failed to load jshint library. Please install jshint in your workspace folder using 'npm install jshint' or globally using 'npm install -g jshint' and then press Retry".
Is there any solution available?
You'll need to follow the prompt and install jshint.
For just the workspace
npm install jshint
or
For all your workspaces
npm install -g jshint
I had this problem while I had installed jshint using yarn globally (yarn global add jshint). I added the following properties to settings.json for User to solve the problem:
"jshint.packageManager": "yarn",
"jshint.nodePath": "/usr/local/lib/node_modules/"
The first property i.e. jshint.packageManager specifies that yarn is used to manage node packages instead of npm. The second one i.e. jshint.nodePath specifies the path of jshint installation. To check if jshint is loaded successfully, I opened Command pallet ( CTRL + 3) and ran command JSHint: Show output which showed this message in the output:
jshint library loaded from /usr/local/lib/node_modules/jshint/src/jshint.js
It indicated that the problem was resolved. Afterwards, the jshint messages appeared in *.js files.
Open cmdr or the Git bash terminal and enter npm install -g jshint, then exit VS code and re-open it.
For applying the changes to Global scope, and not only to a specific Workspace, use the following command in terminal:-
npm install -g jshint
For a particular workspace, use the following command in terminal:-
npm install jshint
Use sudo before npm install jshint
For the current workspace
sudo npm install jshint
or
For all your workspaces
sudo npm install -g jshint
Using sudo with a command in LINUX/UNIX generally gives you the permissions to root level.
The root user has permission to access, modify or delete almost any file on your computer. Normal user accounts can access, modify or delete fewer files. This restrictions on normal user accounts are to protect your computer from unauthorized and harmful programs or users.
Thus, running the installation command with sudo gives you the permissions of the superuser, and allows you to modify files that your normal user doesn't have permission to modify.
Try uninstalling using "npm uninstall" and follow the link - https://marketplace.visualstudio.com/items?itemName=dbaeumer.jshint for reinstalling.

Categories