Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find package.json in directory in CircleCI build

I have a repo that contains two subprojects. Just for completeness a frontend project and a firebase cloud-function project (both using separate package.jsons). Now for this project, I want to start two jobs concurrently. But I can't get the setup done with CircleCI. I don't have any cache-configuration.

project structure

-creepy-stories
  -.circleci
  -cloud-functions
    -functions
     package.json
  -frontend
   package.json

config.yml

version: 2.1
jobs:
  cloud-functions:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories/cloud-functions/functions

    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build

  frontend:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories/frontend
    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build
      - run: npm run test:coverage

workflows:
  version: 2
  cloud-functions_and_frontend:
    jobs:
      - cloud-functions
      - frontend

So now my I guess my problem is the environment cant find my package.json file. The error that is printed looks as follows:

npm run lint

#!/bin/bash -eo pipefail
npm run lint
npm ERR! path /home/circleci/creepy-stories/frontend/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/circleci/creepy-stories/frontend/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2019-04-20T13_08_45_252Z-debug.log
Exited with code 254

I don't know if it is right to set the working directory twice in my configuration, but it is at least set in two diff. jobs.

Update

I managed to get it work if I checkout the root of the Project and then cd to the needed folder and execute the scripts. But this isn't really DRY (don't repeat yourself) maybe some of you have a better solution:

version: 2.1

jobs:
  cloud-functions:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories

    steps:
      - checkout
      - run: cd cloud-functions/functions && npm install
      - run: cd cloud-functions/functions && npm run lint
      - run: cd cloud-functions/functions && npm run build

  web:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories
    steps:
      - checkout
      - run: cd web && npm install
      - run: cd web && npm run lint
      - run: cd web && npm run build
      - run: cd web && npm run test:coverage

workflows:
  version: 2
  concurrently:
    jobs:
      - cloud-functions
      - web
like image 246
MarcoLe Avatar asked Apr 20 '19 13:04

MarcoLe


1 Answers

When you checkout, you automatically copy the root of the git repository into the current working directory. If you want your working directory to be a sub-directory of the root, you need to give the checkout step a path that copies the files into a parent of the working directory.

Example:

working_directory: ~/creepy-stories/cloud-functions
steps:
  - checkout:
      path: ~/creepy-stories

Link to the documentation: https://circleci.com/docs/2.0/configuration-reference/#checkout

like image 112
Brecht Pallemans Avatar answered Sep 30 '22 04:09

Brecht Pallemans