# Building while in deployment with Angular-cli commands?

**URL:** <https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382>\
**Category:** Build Environment\
**Tags:** angular\
**Created:** [October 13, 2016, 3:10am UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382 "2016-10-13T03:10:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gamalielhere](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/gamalielhere/32/14388_2.png) [@gamalielhere](https://discuss.circleci.com/u/gamalielhere)\
**Post date:** [October 13, 2016, 3:10am UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382/1 "2016-10-13T03:10:35Z")

</div>

Hi,  
I’m trying to build the app while deploying but it doesn’t seem to find the commands angular-cli has `ng build --env={environmentName}` as the first command in each deployment returns ng command not found.

---

<div class="post-metadata">

**Author:** ![baruchvlz](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@baruchvlz](https://discuss.circleci.com/u/baruchvlz)\
**Post date:** [November 30, 2016, 6:13pm UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382/2 "2016-11-30T18:13:07Z")

</div>

I know it’s well over a month and I hope you found the answer. But for any future readers:

**ng command** isn’t being found because _angular\_cli_ isn’t installed. My work around for this, and I’m not sure it’s the best way to do it, is to add `npm install angular-cli` to the npm start script.

**EDIT**  
After learning how to better understand CircleCI I found that adding angular-cli as a dependency takes care of `ng` commands, why didn’t I think of this later?

Example _circle.yml_

```
machine:
  node:
    version: 6.8.0
dependencies:
  pre:
    - npm install npm@latest -g # Should fix bug in ng test
    - npm install angular-cli@latest -g
test:
  override:
    - npm run test
```

---

<div class="post-metadata">

**Author:** ![ldirer](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@ldirer](https://discuss.circleci.com/u/ldirer)\
**Post date:** [January 17, 2017, 11:03pm UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382/3 "2017-01-17T23:03:21Z")

</div>

Using `npm install angular-cli@latest -g` in `dependencies -> pre` works, but there might be another way.

Since angular-cli is installed locally the npm scripts in package.json can access the `ng` command (When evaluating scripts, npm adds `node_modules/.bin/` to the PATH environment variable).

```
// This works with angular-cli installed locally only
{
  "scripts": {
    "test": "ng test --watch=false"
  }
}

```

So if you can replace all you ng calls with npm scripts you dont have to install angular-cli globally.

I found it was a nice improvement because angular-cli would take ages (like 3 minutes++) to install globally and apparently would not be cached.

---

<div class="post-metadata">

**Author:** ![ManuChadha](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@ManuChadha](https://discuss.circleci.com/u/ManuChadha)\
**Post date:** [September 5, 2017, 6:24am UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382/4 "2017-09-05T06:24:35Z")

</div>

I tried the script you provided as well following script but I am still unable to run angular cli code in Circle.

dependencies:  
override:  
- nvm install 6 && npm install  
test:  
override:  
- nvm use 6 && ng test

Angular CLI needs node 6 or above but in both the scripts, node 4 gets installed. I have SSHed the machines and verified it. Interestingly, if I manually run `nvm use 6 && ng test` command (after SSH), my angular tests work.

Even though I have specified dependecies section, I notice that ‘npm install’ gets run instead of ‘nvm install 6 && npm install’

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:38am UTC](https://discuss.circleci.com/t/building-while-in-deployment-with-angular-cli-commands/7382/5 "2018-06-18T11:38:47Z")

</div>


