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.
Related
I have npm installed globally and whenever I run npm -v to check its version, it displays it correctly which is currently 7.13.0.
I also have heroku-cli installed globally but whenever I run heroku --version it says:
C:\Users\MyName\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
Inside C:\Users\MyName\AppData\Roaming\npm I have heroku and npm both installed globally but whenever I run a heroku command it fails to run. I am unable to figure out the issue.
Below I have attached the screenshot of my globally installed packages directory.
Maybe your npm's directory path configuration might have some error.
You can modify path by following steps.
Open or create a ~/.profile file and add your npm path
export PATH=C:\Users\MyName\AppData\Roaming\npm/node_modules/node/bin
On the command line, update your system variables:
source ~/.profile
Or else, I recommend changing the npm's default directory which is explained on npm official docs.(https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally). I also had similar issue and followed same instructions.
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.
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.
I've been developing a later-to-be-release Open Source project with Node as a CLI tool. The CLI itself works great I only need to test if it works while on another project, so for that I installed the projects globally npm install -g without errors, but for the life of me I can't use the CLI.
I get the following error:
The odd thing is that the directory and file does exist in the global npm folder:
This is the project's package.json:
Am I not understanding how making a npm/node CLI works? What I'm missing?
EDIT 1:
This is my index.js file:
And this is the commander.js file:
EDIT 2:
After creating a test project as #AngYC suggested I could use the test cli successfully, while inspecting the difference I found this. Inside C:\Users\Ivan\AppData\Roaming\npm the .cmd of both projects are quite different:
EDIT 3 (Solution):
After fiddling around I found out that the file that really needed the shebang (#!/usr/bin/env node) was only index.js file and not the commander.js one. Removing the shebang in that file solved the problem
You may want to try to link your local package to your global executable list.
https://docs.npmjs.com/cli/link
All you have to do is run npm link in the folder you got your tool and it should make the command available globally.
Try to uninstall cli run npm rm -g cli or sudo npm rm -g cli. Then you run: npm install cli -g
If the problem persist, you might want to remove you npm package globally, probably there might be some conflicting things running.
Type this: %appdata% (either in explorer, run prompt, or start menu).
You can simply remove all globally installed npm packages by deleting the contents of:
C:\Users\username\AppData\Roaming\npm
Then you might also want to clear all the your cache run npm cache clear or npm cache clear --force as the case might be.
Then you reinstall all your packages that were install globally again.
If problem still persist, check this:
When you run npm root -g, it yields C:\Users\<username>\AppData\Roaming\npm\node_modules, or even, you should check your path maybe the executable binaries and .cmd files end up in C:\Users\<username>\AppData\Roaming\npm instead of C:\Users\<username>\AppData\Roaming\npm\node_modules, you will need to add that path to the PATH env. variable.
I hope this resolves your issue.
Does npm install only install packages in the directory you run it from? Because that's my current experience with it. At first, I ran npm install xml in a command prompt at C:/Users/ME. Running require("xml"); in a node instance that was run from C:/Users/ME works, and running npm ls lists the xml package...
But if I move to any other directory, neither of them do.
Is this the expected behavior (doesn't sound right), a Windows thing, or am I missing some kind of install option?
Yes, this is normal behavior.
npm install (in package directory, no arguments):
Install the dependencies in the local node_modules folder.
In global mode (ie, with -g or --global appended to the command), it
installs the current package context (ie, the current working
directory) as a global package.
By default, npm install will install all modules listed as
dependencies. With the --production flag (or when the NODE_ENV
environment variable is set to production), npm will not install
modules listed in devDependencies.
NPM Install Docs
npm installs modules either below the current directory (in a node_modules sub-directory) or if you use the -g flag when running it, it install modules in the global location which is determined via OS and configuration and then node.js will be able to find the module no matter where it is being loaded from.
So, this will install a module globally:
npm install -g xml
When using require(), if you want require to look in the current directory to load a module, then you have to do it like require("./module");, otherwise it will not look for the modules install in the current directory.
You need to do npm install -g xml. This would install the packages globally.
'-g' represents global. Then when you check on other directories, you could list the same package
Note the way you install node is important as well!
You can install node with:
chocolatey (https://chocolatey.org/packages?q=nodejs)
nodeJS website (https://nodejs.org/)
*Knowing where to set your user variables is essential know how for windows developers! The reason I mention this is that the list of chocolatey, and node USER : PATH variables gets so large at one point nodejs and with it npm will just stop working. You need to work within your env. variables in one scenario where that happens. (Can typically happen with multiple versions of SQL Server installed)
If you want an excellent free, offline-available resource on node and npm I suggest devdocs (http://www.devdocs.io) and as well GentlNode's cheat sheets (https://gentlenode.com/journal/cheatsheet) *GentleNode not avail. offline FYI.
There's some key information you haven't received yet. See below:
npm install xml - installs "xml" package and required modules to the local folder you are in when you run the command. Files exist for you to work on in this folder alone(and thus commands only work in this folder) and "xml" cannot be called in cmd/terminal outside of this folder(without rerunning with "-g" param) "xml" is NOT written to package.json file. When and if project is uploaded to github will upload in full if you don't add node_modules to your .gitignore file.
npm install -g xml - install "xml" to your global npm folder, which is referenced to your "user environment variables" (what allows you to call specific functions, methods, and executables from within the command line) Files are NOT installed to your project folder, not recorded in "package.json" file. Will NOT upload anything to github.
npm install --save xml - using "--save" allows you to "install" to this folder, but also to write the package you've included into your project's "package.json" file. Here, your aim is to distribute your software and you want as little files on github/source control as possible that npm knows how to install like jQuery, XML, body-parser, etc. etc.
You would typically use a regular "npm install XML" command for a lightweight, rapid release mini-tool to support a key feature or process improvement you just want to keep on your local machine. In addition, you could npm install "packages" to a folder, and use that as a backup "node folder" mapped to your environment variables.
You would typically use a global "npm install -g XML" command for something like middleware, express, node updates installed VIA npm, and other processes you wish to have access to in cmd/terminal from "anywhere." Once this is established for your core development packages in node, you often just use the proceeding command, read the explanation for more detail.
Lastly, you would use "npm install --save" to write into the "package.json" file the required module(s) you've installed to your project. This would be for those who have worked heavily in node and have used "npm install -g" to already globally install their most common core nodeJS. This will write to the package.json the packages and versions being leveraged in your software currently so that your end-user can download the lightweight version and use npm package management to install all of the module dependencies so the app works correctly on other people's computers.
*Note, this leads to the last command "npm install" which you can run in a given folder where you've downloaded the file directly from github.
Hope that helps a bit more for the given facets of installation using npm!