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

Mar*_*oLe 5 continuous-integration yaml circleci

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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

如果我签出项目的根目录然后cd到所需的文件夹并执行脚本,我设法让它工作。但这并不是真正干燥(不要重复自己)也许你们中的一些人有更好的解决方案:

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
Run Code Online (Sandbox Code Playgroud)

Jos*_*ood 2

我认为您已经添加了一个目录。

您应该向 CircleCi 前端任务添加一个额外的运行,先执行 a pwd,然后执行 a ls -la

您可能会发现签出最终位于与您的存储库同名的目录中。

编辑回答后续问题:

如果我没记错的话,签出命令始终将其放在服务器的根目录中,这样您就可以更新工作目录以适应它。像这样

    working_directory: ~/creepy-stories/web
    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build
      - run: npm run test:coverage
Run Code Online (Sandbox Code Playgroud)