ng is not recognised as an internal or external command. Jenkins + Angular CLI
Solution 1
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
Solution 2
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"
Solution 3
npm run ng -- build
we can use as this without installing angular cli
D.B
Updated on June 15, 2022Comments
-
D.B almost 2 years
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
-
hakuna about 6 yearsThis is working but its excluding the additional parameters like --test when running the build
-
apexde over 4 yearsFor everyone who is still finding this post via search, you can check my answer to the question to see how to include additional parameters like --test when running the build (in short, use: npm run ng -- build --test)