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.
Related
I am using yarn v1.6.0 as a dependency manager, I have installed live-server globally by using the following command:
yarn global-add live-server
But when executed it like live server, it is giving the following error:
'live-server' is not recognized as an internal or external command,
operable program or batch file.
It is obvious my path is not configured Can some help which path should I use an environment variable?
I tried to see my version of live-server but got this error,You can use
npm install -g live-server
in your npm command line
All the packages you download from yarn gets stored in bin folder inside yarn directory. So, you have to set the path of the bin folder of your yarn in PATH environment variable as you might have did with the bin directory of the npm.
1). The following path would get you to the bin folder in Windows machine then set this path to the PATH environment variable.
C:\Users\Username\AppData\Local\Yarn\bin
2). For macOS do the following
$ export PATH=$PATH:/home/user/.yarn/bin/
Copy the path of the bin of the yarn.
C:\Users\USER NAME\AppData\Local\Yarn\bin
Go to the Environment variables.
Select, path -> new -> paste the copied path.
Reopen the cmd and type
live-server -v
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.
I have a project which I will have to deploy to client Windows systems where it will not be possible to connect to internet. I currently have a folder in D:\NODE which contains node.exe and npm.cmd and a node_modules folder. To be able to run node from command line I have added D:\NODE to PATH variable.
I can have most of the modules installed locally inside node_modules of my project. However there's one - node-windows - which needs to be installed globally to work.
Following suggestion below I went to node-windows (installed globally) and packaged it up (npm pack), which created a tarball. I have then copied that file with my project and tried to install it on the test machine globally like this: npm install -g node-windows-0.1.5.tgz
I can see that it got installed in the global directory. However when I try to run the command which uses this module it complains that it cannot find it: Error: Cannot find module 'node-windows'
When I list the modules (npm list -g) it is clearly there in the list...
What do you think? And thank you.
You can install packages on a system without internet connection by packing them using built-in functionality in npm. This way, the node modules will be installed properly.
Create a package.json.
In your package.json, list all the modules you need under bundledDependencies (docs on npm).
Run npm install to install your node files before packing.
Create a tarball with npm pack.
Copy the tarball over to the machine without internet connection.
Install the modules with npm install <filename>.
Update
Regarding your comments, it looks like your globally installed node modules isn't found.
Try using the npm link command (docs on npm link):
cd yourAppFolder
npm link node-windows
1 - In system with internet access install module with this command:
npm install [module name]
2 - go to %userprofile%\AppData\Roaming\npm\node_modules[module name]\
(e.g C:\Users\janson\AppData\Roaming\npm\node_modules\grunt-cli)
3 - run npm pack
4 - this should result in a [module name]-x.y.z.tgz file
5 - run npm i -g [module name]-x.y.z.tgz in offline system
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.
I suspect i could have changed where node modules are installed.I have installed express-generator globally.
D:\chirp> npm install express-generator -g
When i try running
D:\chirp> express --ejs
An error popsup in the Command prompt saying
'express' is not recognised as an internal or external
command,operable program or batch file
Here is a screenshot image
Run
npm bin -g
To see where npm installs it's global binaries. Then add that directory to your PATH.
SET PATH=%PATH%;[new directory]
And add it permanently using the way that you should on your system.
simply use
npx express-generator [your projectName]