Can't run npm install

nodejs
circle.yml

#1

my project structure.project structure

this is my basic config.yml

version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:6.10.3

    working_directory: ~/repo
    steps:
      - checkout
      - run: npm install
      - run: npm test

the warning in npm install:

#!/bin/bash -eo pipefail
npm install
npm info it worked if it ends with ok
npm info using npm@3.10.10
npm info using node@v6.10.3
npm info lifecycle undefined~preinstall: undefined
npm info linkStuff !invalid#1
npm info lifecycle undefined~install: undefined
npm info lifecycle undefined~postinstall: undefined
npm info lifecycle undefined~prepublish: undefined
npm WARN enoent ENOENT: no such file or directory, open '/home/circleci/repo/package.json'
npm WARN repo No description
npm WARN repo No repository field.
npm WARN repo No README data
npm WARN repo No license field.
npm info ok 

error in test step:
npm test
npm info it worked if it ends with ok
npm info using npm@3.10.10
npm info using node@v6.10.3
npm ERR! Linux 4.4.0-103-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "test"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! path /home/circleci/repo/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/repo/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/circleci/repo/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/circleci/repo/npm-debug.log
Exited with code 254

Is it a problem with the working_directory variable? if so, how do I point it to my project?

thanks!!


#2

Please use code formatting in your posts here, so your YAML and console IO is readable. Use the code button or indent manually by four spaces…

like this.

Thanks.


#3

If you omit this directive it will default to the root of your project. Unless you are doing something special I would avoid using this since it can get a bit confusing.


#4

thanks for your answer.
If I ommit this directive I got this error:

ERR! enoent ENOENT: no such file or directory, open ‘/home/circleci/project/package.json’

Note that my package.json is inside the lib forder, see the structure of the project attached. How can I modify the value ‘/home/circleci/project’ to ‘/bin’ ? Thanks.


#5

It is best practice to put your package.json file in your repository root. If you have a specific reason to have it in lib, you can use the background key of the run step https://circleci.com/docs/2.0/configuration-reference/#run, but you are likely to run into other issues building and testing your project.


#6

Ok, I’ve moved the package.json file to the root of the directory and CI works now, thanks.


#7