Grunt.js Installation Issue - Command Not Found - javascript

I'm trying to get grunt.js set up on my work machine. Now I've managed to get it set up at home, so I pushed my repository, then cloned it on my work machine, however despite troubleshooting this to death I've always run into the same issue when I come to try and run the command on my work computer;
sh.exe": grunt: command not found
So some background and explanation;
I'm using Aptana 3.0 and running all my commands through the terminal. (This applies to my home and work computer)
I cloned the "working" repository and put it in a folder on my work machine, so I have my package.json and gruntfile.js files inside said directory. These work fine on my home computer and I am able to run the watch task set up in my gruntfile.js successfully at home.
I've run npm install grunt-cli -g and npm install inside my project on my WORK computer and installation has been successful each time. My only error messages on either are a lack of description and a repository field which, to my knowledge these aren't mandatory?
The node modules folder inside my repository indicates I have the following installed (as per my package.json)
grunt
grunt-contrib-compass
grunt-contrib-uglify
grunt-contrib-watch
matchdep
Now I'm pretty green to this command line stuff, so I may have overlooked something very obvious but I feel like I've tried every guide going to get this thing to work.
Despite running through the getting started steps/installing grunt documentation repeatedly, it seems no matter what I do the terminal will not pick up grunt as a recognized command.
Am I stupid or is this some other issue?
EDIT 1: contents of my package.json:
{
"name" : "xxxxxxxxx",
"version" : "xxxx",
"dependencies" : {
"grunt":"~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"matchdep": "~0.1.2"
}
}

This is happening because you are using the Aptana Terminal, which needs the PATH variable to work out what is meant by grunt etc. A normal cmd prompt would work fine with the command npm install grunt-cli -g but in this context the terminal is unaware of what grunt is.
As per the following existing answer, you need to set up your Windows PATH variable to make the Aptana Terminal aware of the npm directory: https://stackoverflow.com/a/19137584/463205
C:\Users\Username\AppData\Roaming\npm
Closing the terminal and reopening it after setting the PATH correctly should enable you to run the command successfully.

Try to run
npm install grunt-cli -g
On your home computer.
-g means - install Grunt globally (not in the project node_modules folder), so it'll add grunt command to the bin folder which is used by nodejs console ( and you need to run node.js command prompt, not just arbitrary cmd)

Related

Node cannot find path in node_modules / 'react-scripts' is not recognized as an internal or external command

I'm on windows 10
When I run:
npm run start
or
npm start
I get an error:
npm start
> app-test#0.1.0 start
> react-scripts start
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
What I already tried:
npm ci
remove node_modules and reinstall project
npm audit fix
run command from elevated PowerShell (as admin)
Uninstall Node v.18 win NVM and reinstall common Node installation LTS v.16
Check if react scripts is on dependencies section in package.json - and it's of course there.
Recreate project itself and also create a fresh new React project with npx create-react-app
Clearing npm cache
Nothing's helped me.
BUT This project runs fine WHEN I explicitly tell the node path to subfolder with a script:
app-test> node node_modules/react-scripts/scripts/start.js
Compiled successfully!
You can now view app-test in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.91.1:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
webpack compiled successfully
What's interesting that an old React projects also resided in the parent folder starts normally even I renew node_modules in these projects doing them npm i or npm ci
But any time I try to create and start new React app command npm start fails
UPD1: Tried to create-react-app on any other drive or folder. And it's running ok.
So culprit seems permissions policies in my common working directory ?
UPD2:
I resolved a problem though still have no clear idea who was actually the really culprit of this bug.
I copied all my parent developer folder with all code examples to another drive, then tried to create react app there and out of the blue it worked fine at then new location.
Also I removed this original folder from the drive where it used to be. And do git clone "..." at this directory< recreating the exact structure as it was before all experiments.
Then I tried create-react-app exactly at that location as I've unsuccessfully tried before swapping folders and it was OK !
Tried couple of time with different folder location within parent directory and all sill working fine now !
I remembered now I already have such bug before. And I had to reinstall Windows that time.
I also want to mention that I also have another machine with Windows, another one with Linux and had also laptop with an OSX so I can ( or could) push to this very git repository from any of these computers.
Suggestion of somebody who have any idea, why this bug was happening repeatable would be highly appreciated.
Thanks.

Javascript issue installing npm packages (nodemon, express)

I'm new to js and trying to setup a simple project with express and nodemon via npm.
However, installing these packages does give me multiple errors (see below).
I am on Win 10, using the PowerShell & Atom IDE. Project is saved on Google Drive.
"Calc.js" is simply the name of my project.
I have node & npm installed and restarted pc multiple times before.
Then I set up the npm init
I begin to install the first package and get this error:
I try to install express, but get the same result, adding -g also does not make a difference. Now I install "ci", which works for some reason.
Now I have the node modules folder in my project, try to install express again, and it seems to kinda work (got the files in the node_modules folder).
However when I try to run the calc.js via "node calc.js" it
does not work.
Already tried out many things and even accidentally made it work, then tried to reproduce it and failed. Would be super happy for some help.

'firebase' is not recognized as an internal or external command, operable program or batch file

I am in a bizarre problem, I just updated my Node.js and NPM at the date of 01-Feb-2019. And used the following command-
npm install -g firebase-tools
to install the Firebase CLI
Then on typing either of the code below
firebase login
or
firebase init
it is showing the following error
'firebase' is not recognized as an internal or external command,
operable program or batch file.
Please help me. It has already consumed my two days.
npm install -g firebase-tools -f
Using -f for force install again.
This work for me
Ok. First of all, Bizarre problem has some bizarre solution.
Uninstall your node js and NPM completely.
Then reinstall it, and check, whether it works or not.
Best of Luck
If you are using MS Windows:
Open Start Menu or press Win button on your keyboard.
Type "variables".
Click on "Edit the system environment variables"
Click on "Environment Variables..." button.
In the "System variables" list select "Path" and click on the "Edit..." button under the list.
In the "Edit environment variable" dialog click on the "Browse..." button.
Navigate to the c:\users\<yourusername>\AppData\Roaming\ dir and select the "npm" sub-dir, then click "OK".
In the "Edit environment variable" dialog click "OK".
In the "Environment Variables" dialog click on "OK".
For the Linux users:
Navigate to the home_dir.
Edit the hidden ".bash_profile" file.
Add line with following text "export PATH="$PATH:/usr/local/bin".
add to .bash_profile
export PATH="$PATH:/usr/local/bin"
and run
npm install -g firebase-tools
this worked for me
Navigate to the firebase directory and call it out on the cmd.
run cmd as admin
cd C:\users\yourusername\AppData\Roaming\npm
firebase.cmd login or firebase login
firebase will prompt a google login after which the issue should be resolved.
There you go. above steps are all commands goes to your command prompt.
After running npm install -g firebase-tools, go to C:\usr\local. You will see Firebase files.
Copy this path C:\usr\local to the clipboard.
Open the Start Menu and search for Edit the System Environment Variables or simply env.
Select the environment variables option that appears.
Find the PATH variable under the system environment variables (lower section).
Select PATH and click Edit
Add C:\user\local to the beginning of the path.
Add %APPDATA%\npm if it doesn't exist.
Click OK to each of the windows until they're all closed.
After this, open a Windows command prompt and run firebase --version.
My solution is to use Firebase CLI binary for Windows:
Download CLI: https://firebase.google.com/docs/cli#install-cli-windows
Run CLI, go to the project directory (cd 'your app path'). By the way, you may see the version: run "firebase --version" for that
Run "firebase login" with Firebase CLI
Run "firebase init" with Firebase CLI
Make sure you are running command line as an administer.
Make sure you run the CMD in administrator mode. Also once you have run
npm install -g firebase-tools commands close the CMD prompt and reopen again. If this doesn't work uninstall node and reinstall it again. It requires your node version to be a minimum version to support firebase.
After installing
$ npm install -g firebase-tools
Note the directory where it installed
What I did was locate the directory where firebase was installed. In my case C:\usr\local then I copied the three firebase files. I also went into the node_modules folder and copied the firebase tools folder. Then I went to my app directory in file manager and pasted the firebase files, then created a new node_modules folder and pasted the firebase-tools folder.
Now go to your cmd and run
$ firebase init
It should work
1.After installing firebase globally via npm i -g firebase-tools
2.simply run all your firebase commands from the node command-line tool, it instantly worked for me.
3.To access the node command line, simply go to the start menu on windows and type "node.js command prompt"
Add this to the environment variable:-
C:\Users\<user>\AppData\Roaming\npm\firebase
it will allow firebase commands in ps/cmd
i dont think : C:\Users<user>\AppData\Roaming\npm\ now works.
I was struggling with this same issue for a few days and had an issue where my NPM was installed in two different places for whatever reason.
I had an npm folder in C:\Users\<user>\AppData\Roaming\npm\ as well as C:\Users\<user>\npm\
Turns out the Firebase installation command installed all the needed files into the latter folder, while my Environment PATH was pointing to the first folder.
I changed my PATH variable to C:\Users\<user>\npm\ and ran the firebase installation again. After that everything started working fine.
If you havent checked the other answers about what PATH is, you can access it by typing env in the Windows search bar and from there click the Environment Variables button. Then double click the Path line under System variables to edit it. Remember to press OK to save any changes.
This is probably a rare edgecase, but maybe it will help someone.
For peeps like me who were unable to get rid of this problem after trying everything suggested above.
I know it is late but I Fixed it by changing the location for installing my packages.
I ran the command "npm config get prefix" in cmd and I found out that my default location for node_modules installation had been changed.
so I set it back to default by "npm config set prefix "C:\Users\your_PC_Name\AppData\Roaming\npm".
After that I used "npm install -g firebase-tools" again
My firebase package was installed. I was relieved to see firebase.cmd file in npm folder.
Earlier I had tried every thing like uninstalling node.js and deleting npm and npm cache folders but all those methods didn't work for me.
Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)
this discussion worked for me only.
all of the Simple and Quick solution is here... step1): just go to C:\Users\your-user-name\AppData\Roaming\npm step2): copy the path of this "npm"-folder step3): now go to start and type "env" and select first-option then step4): now paste that path in "paths"-option by clicking on "edit"-button step5): then click on "ok" and restart your pc
I had similar issue in MAC. Terminal was giving me command not found message on running "firebase --version". So, I tried to reinstall the firebase with the command: "sudo npm i g firebase-tools" but it again errored out stating that the installed firebase binary file is corrupted.
Solution:
STEP 1. Provide read, write and execute access with "sudo chmod a+rwx configstore" cmd to the path :
"/Users//.config/configstore/"
STEP 2. Run following command to update firebase:
sudo curl -sL firebase.tools | upgrade=true bash
Add C:\users\yourusername\AppData\Roaming\npm to your environment variable PATH.
For anyone still fighting this problem try to add the system environment path not to
a user's environment.
https://github.com/firebase/firebase-tools/issues/46#issuecomment-615534999
Run your cmd from C:\Windows\System32\cmd.exe or type this in your file path and hit Enter
Just reinstall firebas-tools {npm i firebase-tools -g} globally
Restart your computer its work for me good luck
Simple answer to this question is-
1.npm install firebase command in terminal window.
2.Add firebase scripts in your editor that you use.
3.set the Path in the environment system variable.
I think it will be able solve your problem...
My solution was that my project was on partition F: somedirectory/app, and when I moved it on partition C: Users/username/Documents/app It worked!
I tried everything mentioned and more, lost couple of hours.
So moving on partition where I installed: npm install -g firebase-tools
then: firebase login, then: firebase init
npx firebase <your command>
If you have similar problems like this
firebase : File C:\Users\<user-name>\AppData\Roaming\npm\firebase.ps1 cannot be loaded because running scripts is disabled on this system. For more em. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ firebase login
+ ~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
perhaps you can try to Ctrl + Click the C:\Users<user-name>\AppData\Roaming\npm\firebase.ps1
After that you'll see a new PowerShell Terminal and you can continue it.
Hope it's works

Can't get Grunt to run

I'm a little confused as to why I can't get my Gruntfile.js to run, here's the rub:
I installed grunt globally using npm. It lives in my /usr/local/bin/ directory, here it is:
Previously, I'd installed node.js using homebrew, then grunt with npm. Other issues led me to uninstall node via homebrew & reinstall node directly from the disk image node provides.
In my web project's index, there's a Gruntfile.js script that rebuilds my jekyll site everytime live-reload updates. When I run grunt, I get this message:
What I'm trying to wrap my head around:
Why isn't /usr/local/bin/grunt a valid path? Grunt exists at that location. My guess was that running grunt locally, from within my website's index, would fix things.
There's a node_modules folder there & everything was working fine before after all. I found this link, and tried running \grunt to bypass the bash alias, but that had no effect.
Any advice/suggestions are much appreciated! I feel like an imbecile using things, breaking things & not understanding why/how. Eager to finish my project, get a paycheck & finally have time to learn the ins and outs of terminal, bash & popular package managers so I don't run into these sorts of problems...
After discussion with OP, I find this is a Node.js environment issue. After install - do something - uninstall - reinstall in another way - do something, somehow, when npm install -g XXX is executed, the symbolic link is created and point to some place, but the package is installed some where else. That's why OP see /usr/local/bin/grunt but cannot run it.
I've recommended OP to clean up all Node.js stuff, make a clean environment and start right from the beginning.

Not Getting $ in command prompt in Node.Js

My NodeJs is working fine but i have an issue I'm not seeing $ in the prompt as most example point.
Another issue is when i put sudo I dont get anything.Things I have tried are the following
$ sudo npm install npm -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
npm#2.7.1 /usr/lib/node_modules/npm
given on the following Website
http://www.tutorialspoint.com/nodejs/nodejs_npm.htm
Apologies am very new to Node.JS.Please help
I'm going to explain this in terms familiar to MS windows.
$ npm --version
^ dollar sign is the same as "C:\" in windows.
It just means "from here..." in the most basic terms I can use.
You don't need the dollar sign for anything in that tutorial.
"sudo" means "elevate to an administrator level" similar to opening a command line terminal "in administrator mode." But for Linux (Ubuntu and Mac as *NIX) systems.
--version can be called as "-v" most of the time and means "for the thing I've named before, in this case "npm" show me the version.
Once you've installed NodeJS it comes with a "package manager" called NPM. The best way to relate this to windows is by considering it a command line version of an "installation" that installs different programs as you tell it to with different options.
"npm install -g" means "Hey NPM! Install to EVERYWHERE(call from command line/terminal/bash) the thing I Tell you next. "npm install -g express" for example, means hey NPM, install "expressJS" globally, so I can use the terminal to write commands(micro apps) from the expressJS I just installed with node.
"npm install --save" means hey, install this microapp, but ONLY let me use it in THIS EXACT FOLDER I'm in, and let anyone else that is in this folder know they need to install it to use this application I'm making.
"npm init" Is actually the FIRST thing you should do in any node project folder. It creates the "package.json" file in the current directory, and it will define the folder you're in as the folder to start installing stuff you "npm install" to the "node_modules" folder that will show in the folder you're currently in.
If you want to tinker with NodeJS code, and you don't want to tamper with your local machine and install all kinds of stuff you're not totally sure about yet you can use "REPL.it" (https://repl.it/languages/nodejs) the white window on the right is treated like a file you'd run in node. The dark window on the right is an actual NODE TERMINAL that you can run nodejs commands/code in directly.
There's one other good resources in general and that is here (https://devdocs.io/) it's called "Devdocs" and it has Node, npm, and express code examples, clean explanations, and examples that you can download directly to your local machine.
I hope that gets you moving with NodeJS. It's hard to understand, but with a bit of try and fail you'll start to try more and fail less. Cheers!

Categories

Resources