Running karma after installation results in 'karma' is not recognized as an internal or external command - node.js

I'm trying to run karma as part as an angular-seed project, after installing karma using
npm install -g karma
I get:
'karma' is not recognized as an internal or external command, operable program or batch file.
when i'm trying to run test.bat from angular-client\scripts, the content of this file is:
set BASE_DIR=%~dp0
karma start "%BASE_DIR%..\config\karma.conf.js" %*
I also tried to navigate to "\AppData\Roaming\npm\node_modules\karma\bin" and saw karma file, when I'm trying to run it I get again:
'karma' is not recognized as an internal or external command, operable program or batch file.
Any suggestions?
If not please suggest how to use jasmine without karma.
Thanks.

The command line interface is in a separate package.
To install this use:
npm install -g karma-cli

karma-cli
It is recommended to install karma with its Command-Line-Interface (karma-cli) which will take care of fetching the appropriate karma. You can also install a different local version specific to each project you're working on and karma-cli will pick the appropriate one.
From the karma installation page:
Typing ./node_modules/karma/bin/karma start sucks so you might find it useful to install karma-cli globally:
npm install -g karma-cli
Now, check that karma was installed by typing:
which karma //echo something like: /usr/local/bin/karma
and check that karma server is working (ctr+c to quit):
karma start
You can also check that karma was installed by going to this directory:
cd /usr/local/lib/node_modules/karma
Good luck!

On windows when you install a npm (non-globally - so without the -g flag), the executable commands are linked in the node_modules\.bin folder.
For example:
powershell> .\node_modules\.bin\karma start
powershell> .\node_modules\.bin\karma run

I had the same issue and fixed it by correcting my PATH environment variable.
STEP 1: go to the following path and ensure karma.cmd is present at the location given below
[Nodejs folder path]\node_modules\.bin <=> C:\Program Files\nodejs\node_modules\.bin
STEP 2: If present go to STEP 3, If not present run the following command npm install -g karma
STEP 3: Open environment variables and edit PATH
STEP 4: Add the following at the end :
[Nodejs folder path]\node_modules\.bin; <=> "C:\Program Files\nodejs\node_modules\.bin"
Log out your session and it will work for sure.

Based upon your directory using \AppData\Roaming, you're on Windows and this error is usually because the path to the npm globals isn't in the Windows PATH or NODE_PATH environment variables.
Use SET to check the values you are using for the paths and if your npm directory isn't listed, that will be the issue.
If you don't want npm to save to this directory, check the npm configuration options and the npm folders docs to see what you can change in this regard...

'karma' is not recognized as an internal or external command, operable
program or batch file.
If the above mentioned solution does not work, than
The cause of issue is previous version of nodejs. So uninstall the previous version of nodejs and re-install the latest version. It will resolve your issue. As I faced the same and by doing above changes it worked for me.
Thanks.

Official documentation at https://karma-runner.github.io/0.12/intro/installation.html is confusing. It implies that npm install -g karma-cli is to install karma globally but it actually required for to run karma from command line.

I had same: 'karma' is not recognized as an internal or external command, operable program or batch file. problem when i tried to install it directly to my project file. When i used npm install -g karma-cli to global install everything worked just fine.

Related

"vite is not recognized ..." on "npm run dev"

I'm using Node.js and npm for the first time, I'm trying to get Vite working, following the tutorials and documentation. But every time I run into the problem 'vite' is not recognized as an internal or external command, operable program or batch file. I have been trying to find a solution for 4 hours now but with no results.
I tried restarting pc, reinstalling node.js, several procedures to create vite project but in vain. I suppose it's my beginner's mistake, but I really don't know what to do anymore.
Commands and responses I run when I try to create a vite project:
npm create vite#latest
>> my-portfolio >> vanilla & vanilla
cd my-portfolio
npm install >>resp: up to date, audited 1 package in 21s found 0 vulnerabilities
npm run dev
resp:
> my-portfolio#0.0.0 dev
> vite
'vite' is not recognized as an internal or external command,
operable program or batch file.
try to install the packages to make it work
npm install or npm i
For this error use the following command on your terminal in the present working directory of the project
npm install
npm run dev
first, try to install a node package manager and then run npm run dev hope it will work
yarn add vite
on project folder to add vite,
and run
npm run dev
again.
remember to update your node version to 18, LTS from 17 might not support this installation.
update:
I try to fresh install again my Laravel 9.19, since i had update my node to version 18, npm install & npm run dev just work fine without yarn.
According to documentation https://vitejs.dev/guide/#community-templates
npm install
npm run dev
npx vite build
I found myself in the same situation.
The problem is vite.cmd is not in the system or user PATH variable, so it cannot be found when it is executed from your project folder.
To fix it, you should temporarily add the folder where vite.cmd is in your PATH variable (either for the entire system or your user). I recommend adding it just for your user, and keep in mind you should probably remove it after you stop working on that project, because this could affect future projects using the same build tools.
To do this:
My PC > Properties > Advanced system settings > Click on Environment Variables (alternatively just use the start button and begin typing Environment, you should get a direct link)
On "User variables" find "Path" and edit it.
Add a new entry for the folder where vite.cmd is. Example "C:\dev\reactplayground\firsttest\test01\node_modules.bin" Check your project folder to find the right path.
Make sure your close and open your console for this change to affect.
Go back to your project root folder and run "vite build", it should work now.
for me I've:
1 - excuted yarn add vite
2- and then npm install
work fine !
For me I had a project I created on one computer and it had this in devDependencies:
"vite": "^3.1.0"
I did pnpm install and it reported everything was fine, but I was getting the error. I ran pnpm install vite and it installed it again with this:
"vite": "^3.1.8"
After that it worked fine. So try using npm, yarn, or pnpm to install the vite package again and see if that works.
try npm install
then npm run build
Recently faced this error and I run
npm install
npm run dev
then the output was
VITE v3.2.4 ready in 1913 ms
THAT'S COOL 😎😎😎
reference LINK
You need Node version 15 or higher, I had the same problem because I was using an older version of it.
Needs to install all the packages in package.json and run again
npm i
npm run dev
For me this worked:
I changed NODE_ENV environment variable to development ( earlier it was production - which should not be the case, as dev-dependencies won't get installed by npm install or yarn )
Here is what to make sure before running npm install or yarn:
Make sure `NODE_ENV` environment variable is not set to `production` if you running locally for dev purpose.
'vite' is not recognized as an internal or external command, operable program or batch file.
> vite
'vite' is not recognized as an internal or external command,
operable program or batch file.
try to install the packages to make it work
npm install or npm i
The following works just fine!
npx vite build
npm i
npm run dev
I had the same challenge and I was finding the error
create-vite : command not found
I resolved by running the command:
npm i create-vite
From there you can continue with running the command:
npm create vite#latest
Reference:
https://www.npmjs.com/package/create-vite
npm install or npm i
helps with issue of 'vite' is not recognized
After I tried npm install
i could run the npm run dev after and it showed me the localhost

nmp install -g under Windows 10, not recognized as a command

While logged in to Windows 10 as a User, and opened the command prompt as an Adminstrator, cd to my nodeJs project directory and did npm install browser-refresh -g in order to install the browser-refresh package from the npm which went ok but with some "npm WARN deprecated" messages. and the confirmatioin
browser-refresh#1.7.3
then I modified my code according to the package instructions and did browser-refresh index.js which suppose to replaces node index.js but I get the error
'browser-refresh' is not recognized as an internal or external command, operable program or batch file.
So I installed it locally with out the -g tag for no avail. I able to run it using the command C:\Users\adminName\AppData\Roaming\npm\browser-refresh index.js
I added the path above to the list of Paths under "System variables > Path" for no avail. I may un install the local package since that did not work. Someone please suggests a working solution.
Even though I get it running with the long command, the pacakge did not refresh the web page after changed the index.html file and saved it but this may be a different question.
Thank you
The path to the NPM bin folder may not be defined in your PATH environment variable. You can test this by installing another package that should be executable from the command line and checking to see if executing it results in the same error.
If it does, you can "%AppData%\npm" to your PATH. Here are instructions on how to do so.
Hope this helped!

Why "artillery" is not recognized as an internal or an external command?

I want to use artillery to test a nodejs app,
I installed artillery.io globally and I added the path to the environmen variables, but I still get the error
"'artillery' is not recognized as an internal or external command,
operable program or batch file.". I can't find similar issues on the web.
I couldn't install it in cmd first either, but then repeating same installation steps through Powershell (run as Administrator) worked fine.
Being:
install: npm install -g artillery
check installation: artillery -V
Look in the folder pointed out by
$yarn global dir and see if that folder is in your $PATH.
Or you can specify the a prefix when adding the package like below.
$yarn global add artillery --prefix /usr/local
you need to set environment variable path of npm
and my system npm path is "C:\Users\RanjitBarsa\AppData\Roaming\npm"
hope this works!!

Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)

Running nodejs on Windows 7 Enterprise at work.
Whenever I install a node_module that needs -g access, from experience I know it's supposed to create a *.bat file in %AppData$/Roaming/npm, but for some reason it no longer does that.
For example, I will run npm install gulp -g, console looks like it installed correctly, but the files will not be in the AppData folder. And if I try running a gulp command, I get error sh.exe": gulp: command not found.
If I run the npm install gulp -g command in Console As Administrator, it installs the files into the %AppData% folder of the administrator (instead of the regular user). So if I run the gulp command through my non-administrator user, I still get error sh.exe": gulp: command not found.
Any ideas?
Found solution:
(1) Upon running the command: npm config get prefix, output is C:\Program Files (x86)\Git\local. No idea why it was set to this, as it's not the default.
But I changed it using: npm config set prefix "$APPDATA\npm".
Now when I install a --g module, ie. npm install gulp -g, it installs into this desirable directory, no longer throwing EPERM and ENOENT errors.
(2) Still need to add a PATH entry for the npm folder. The command export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm works temporarily, but if you close console and open it again, might not be saved (if you are not an administrator).
But you can also use echo 'export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm' >> ~/.bash_profile, which will create a .bash_profile file, which is run each time as your console is opened. So from this point, it should automatically add the required PATH entry.
I also faced this same issue.
After installing node.js(https://nodejs.org/en/download/) npm folder(in appdata folder) remain empty.
so, at this stage if you try to build/run angular project(ng build/ng serve), it will give error as:
The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program.
So, for fixing this issue install angular globally in your project with following command:
npm install -g #angular/cli
Now, there would be data in npm folder(node modules etc.) and ng command will run now.

Using GRUNT from NodeJS error message "'grunt' is not recognized as an internal or external command, operable program or batch file"

The webproject that I am working on uses SASS which is compiled into Grunt tasks, and grunt is supposed to run in NodeJS.
I have been given these instructions but it's not working:
I installed NodeJS (default folder/settings)
I then went in my project folder in CMD C:\Users\Ben\Desktop\officeincambridge>
Then ran the command npm install -g grunt-cli
and npm install grunt
If I type NPM version (in dir above) I get npm --version: 1.4.14 , node --version: v0.10.29
However, when if I try and compile the files using grunt sass i get this error message 'grunt' is not recognized as an internal or external command, operable program or batch file.
Can anyone assist me on how to use it (I have never used grunt before). HERE are the instructions which I am using.
Thank you
Try to install
npm install -g grunt-cli
This seems to be a duplicate of this question: Grunt on Windows 8: 'grunt' is not recognized
In his case, it was a PATH issue. Check that your PATH is correct. It must contains the path where npm is installed: C:\Users\Ben\AppData\Roaming\npm
I also had the same issue :
To Solve this
I have added "grunt path" in SYSTEM environment Variable .
C:\Users\\AppData\Roaming\npm\grunt
To find your grunt path Use Command(in cmd) : where grunt
Once Added Path to SYSTEM Environment Variable Restart Jenkins and build job again

Resources