NPM can't be found by circle

nodejs
npm

#1

Hi there!

I’m starting to use circle 2.0 and faced specific failure. npm install returns

#!/bin/bash -eo pipefail
npm install

/bin/bash: npm: command not found
Exited with code 127

What’s going wrong?

version: 2
jobs:
  build:
    docker:
      # documented at https://circleci.com/docs/2.0/circleci-images/
      - image: circleci/elixir:1.4
      - image: circleci/postgres:9.4
      - image: circleci/node:6.10

    working_directory: ~/brutalist
    steps:
      - checkout

      # Node
      - run: npm install
      - run: npm build:frontend

      - save_cache:
          key: node
          paths:
            - node_modules

      # Elixir
      - run: mix deps.get
      - run: mix ecto.create
      - run: mix ecto.migrate

      - save_cache:
          key: elixir
          paths:
            - _build
            - deps
  test:
    docker:
      - image: circleci/elixir:1.4
      - image: circleci/postgres:9.4
      - image: levlaz/elasticsearch-docker-ci:5.1.1
    working_directory: ~/brutalist
    steps:
      - checkout

      - restore_cache:
          keys:
            - node
            - elixir

      - run: npm run link
      - run: mix test

Build link: https://circleci.com/gh/asiniy/brutalist/15


#2

@asiniy This is because the Elixir Docker image does not have npm installed. If you look at the documentation for “Specifying Container Images”, under the heading “Using Multiple Docker Images” it explains that listing multiple container images should be used when you have external services you depend on (such as a database or caching system). It’s not designed for when you have secondary languages to support.

In a multi-image configuration job, all steps are executed in the container created by the first image listed.

Your solution is to either install npm as part of your CircleCI run when the Elixir image runs or build a custom Docker image containing all the necessary components you need for building and testing your application.

I’d recommend you take a look at the following topics with issues similar to yours:


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.