Ng: command not found (angular-cli & yarn)

I’m trying to test the speed improvements of Yarn vs npm.

In this project, with npm I was using the following file:

machine:
  node:
    version: 6.5.0
test: 
  override: 
  - ng test --watch=false

Now, following the docs, trying to use Yarn, I’m using this config in circle.yml

machine:
  pre:
    - mkdir ~/.yarn-cache
  node:
    version: 6.5.0
dependencies:
  pre:
    - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
    - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    - sudo apt-get update -qq
    - sudo apt-get install -y -qq yarn
  cache_directories:
    - ~/.yarn-cache
  override:
    - yarn
test:
  override:
    - ng test --watch=false

But in the ng-test I get the following error:

bash: line 1: ng: command not found

ng test --watch=false returned exit code 127

angular-cli is listed as a devDependency in the package.json, so the yarn command itself should install it, just as the npm install did with npm, right?

I don’t think this has to do with yarn. I am a bit confused on how this ever worked.

ng test assumes that ng is installed globally. Otherwise you would need to to execute the absolute command node_modules/angular-cli/bin/ng unless you are calling it as a part of a script from package.json.

Could you share your circle.yml from when you were doing this without yarn?

Ultimately there are two options (as far as I know)

  1. Install angular-cli globally npm install -g angular-cli so that you can call ng from any context
  2. Make a script in package.json such as:
{
  "scripts": {
    "test": "ng test --watch=false"
  }

and then execute it with

test:
  override:
    - npm run test

Update

I ran a build using just npm and it totally works just like you said.

Update 2

I see whats is going on here. The reason why “plain” npm just works is because our inference engine is exporting node_modules as a part of the build dependency step. When you run override it no longer runs this step so then the node_modules dependencies are no longer in the PATH.

So the way to get this to work would be:

  1. Add node_modules/.bin to the PATH
  2. Make a script in package.json
  3. Install angular-cli globally
1 Like

Oh, you are right! I think the first approach ( making a script in package.json) would be a better approach, because if I have to install globally angular-cli with every build I’ll lose like 30-60 seconds.

Do you know if pre-installing Yarn in machines is on the roadmap of CircleCi?

Thanks for your help!

1 Like

My pleasure!

Yes for sure, I am working with the build image team to get this done in the next image update.

Please keep in mind though that having it pre-installed will not address this specific issue. We would need to update our inference engine to handle yarn in order to make this completely automated.

1 Like

Perfect :slight_smile:
Thank your for your help :smiley:

1 Like