Why can't I run npm or ng commands?
I install NodeJs folder & created a TestApp_50_Angular project using visual stuido
folder
I am setting up env variables here
Related
I know this question has been asked already, but the reply was not helpful to me.
I try to run an Angular app in electron by typing in Visual Studio code integrated terminal the following command:
npm start
The error I get is:
'ng' is not recognized as an internal or external command,
operable program or batch file.
The log file looks as following:
Now:
I have node installed:
Running command node -v gives me - v8.9.4
I have angular Cli inatalled.
Running the command npm list #angular/cli
gives me: `-- #angular/cli#6.0.3
I went to the folder of Environment Variable
The PATH variable looks as following:
C:\users\dim\AppData\Roaming\npm\node_modules\#angular\cli\bin;C:\Program Files (x86)\Microsoft VS Code\bin
What else can I do in order to solve the issue?
Your PATH variable should not contain C:\users\dim\AppData\Roaming\npm\node_modules\#angular\cli\bin but C:\users\dim\AppData\Roaming\npm.
Here are the .cmd files that are created when you install libraries globally :
npm i -g #angular/cli#latest
I am trying to setup Jenkins for an Angular CLI project. I have installed node and Angular Cli on the Jenkins server under a specific user account.
if I open a command prompt on the server an execute the following commands to verify they are installed properly, this is the result:
I have configured the project with Jenkins, and i created two build steps two execute two bat files.
One runs: npm install
and the second one runs: ng build --prod
Then I build Jenkins, it runs the npm install but it fails running ng build --prod because it says " 'ng' is not recognised as an internal or external command".
Am I doing something wrong? Is there another way to probably use the angular cli on the node_modules folder, So it does not need to use the angular cli installed on the server. It seems like Angular CLI is installed only for my user on the server but not for the user Jenkins use to build.
PS: I installed Angular CLI globally using:
npm i -g #angular/cli
No need to install angular cli on server, just run
npm run ng -- build
That will run the local version from your project devDependencies
This way you can pass any flag to your local cli npm run ng -- test, npm run ng -- lint, etc
You can pass additional flags to ng just like that
run ng -- build --prod
More details at https://docs.npmjs.com/cli/run-script
Just for further clarification when someone searches for the same problem and finds this question (as I did):
If you want to use the --prod flag while running the build command, as asked in this question, you can use:
npm run ng -- build --prod
Important are the "--" between "ng" and "build" with spacing. This is due to the syntax of "npm run", more information can be found here: https://docs.npmjs.com/cli/run-script
This also solves the problem described in a comment below the accepted answer: "This is working but its excluding the additional parameters like --test when running the build"
npm run ng -- build
we can use as this without installing angular cli
If it is working on the Local command prompt, Restart the Jenkin server.
Restart Jenkins --> http://host-name:port/base-url/restart
ex:- http://localhost:8080/jenkins/restart
If it is not working on local command as well install angular CLI globally and set the environment settings and do the previous step.
try as below.
BUILD_ID=dontKillMe nohup ng serve
The only issue with npm run ng build is it omits any other parameter like --prod or --test after build.
Following are the commands what i am using to run my angular build successfully from Jenkins.The last command is executed the dirty way by setting up the path variables. Don't know if there is a cleaner way to do this. This does execute the commands properly without omitting anything.
#echo on
cmd /c npm install -g #angular/cli#latest
echo yarn Install
cmd /c yarn
echo Build
set PATH=%PATH%;C:\Users\Administrator\AppData\Roaming\npm;C:\Users\Administrator\AppData\Roaming\npm\node_modules\#angular\cli\bin;
ng build --prod --aot=true
I'm pretty new to Angular 2 and I just started to learn it. After doing this:
npm install -g angular-cli - I couldn't find on the hard drive this folder: src/app / ./src/app/app.component.ts.
My question is - in order to open the files in notepad++ - how can I locate it on my hard drive? I looked in program files / nodejs but it wasn't there
Thanks
npm install -g angular-cli has installed the angular command line.
You don't have any created project yet.
What you need to do next is run the following commands:
ng new your-app-name // create the app with angular-cli
cd your-app-name // change directory to your new angular app
ng serve // run your new angular app
Check the official site here: https://cli.angular.io/
I have following project structure:
-app
-client
-server
I need to run npm install from server folder (i have build script)
So i running
npm --prefix "../client" install
But instead of going to parent folder, npm creating folder with .. name and client inside. And trying to run npm install there. And installation fails because package.json is not there.
On linux its working fine.
How can i define relative path from parent folder ?
I am new to gulp and I am facing problem in integrating it with msbuild. I am trying to run tasks using gulp(e.g: minifying files) and even though it works perfectly when I build my project,it fails to run on msbuild.
Here is the code for gulpfile.js:
var gulp=require("gulp"),
gutil=require("gulp-util"),
uglify=require("gulp-uglify"),
debug=require("gulp-debug"),
concat=require("gulp-concat");
var uglifycss = require('gulp-uglifycss');
gulp.task("js",function(){
gulp.src(["./**/*.js","!./**/*.min.*","!./**/gulpfile.js"])
.pipe(uglify())
.pipe(debug())
.pipe(gulp.dest(function(file){return file.base}));
gulp.task('css', function () {
gulp.src(["./**/*.css","!./**/*.min.*"])
.pipe(uglifycss())
.pipe(gulp.dest(function(file){return file.base}));
});
gulp.task("build",["js","css"]);
gulp.task('default', function(){
gulp.run('build');
});
this is called by a powershell script file compileClient.ps1:
npm install -g gulp
npm install --save-dev gulp gulp-util
npm install --save-dev gulp-uglify gulp-concat
npm install --save gulp-uglifycss
npm install --save-dev gulp-debug
gulp
npm install -g rimraf
cmd /c $env:APPDATA\npm\rimraf ./node_modules
when I run this command on cmd,
"%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe" -file "$(ProjectDir)compileClient.ps1"
It works fine and minifies the target files. I then tried putting this command in the post build event of my project and when I run it locally on visual studio it works fine too.
however when this project is built by msbuild, the same post-build event does not work,it gives the following message shown in the image below:
npm : the term 'npm' is not recognized as the name of a cmdlet..
I checked the PATH variable set by node and it is correct. Also when I do node -v on my cmd I could see the version of node installed, but when I do it on the msbuild command line it fails to identify node.
I used this blog as a reference
https://www.niclassahlin.com/2015/04/10/running-gulp-during-tfs-build/
I would appreciate any help/advice on this matter, thanks.
You can use Node.js installer to install npm, npm will be available for all users after this.