Npm run build fails intermittently with status code 1

I am using circleci to build and deploy a node app. Everything works great until I run npm run build. Sometimes, it succeeds and sometimes it fails with status code 1. There is no logical reason for the inconsistency.

I reached out to support but they haven’t responded for 2 weeks. I do not understand the problem since it is running perfectly in local machine and there’s no error output except the status code.

Am I missing anything?

  build:
    ...
    steps:
      - checkout
      - run:
          name: Install tools
          command: |
            apt update
            apt -y install --no-install-recommends lsb-release apt-transport-https cron coreutils ca-certificates curl tar gzip wget gnupg2 nano bash p7zip-full apt-utils
            curl --silent --location https://deb.nodesource.com/setup_22.x | bash -
            apt -y install --no-install-recommends nodejs
      - run:
          name: Authorize to NPM package
          command: |
            echo "//npm.pkg.github.com/:_authToken=${GITHUB_ACCESS_TOKEN}" > ~/.npmrc
            echo "@eatzy:registry=https://npm.pkg.github.com" > app/.npmrc
      - run:
          name: Set package version
          command: |
            cd app
            cat package.json | sed "s/\"version\":.*/\"version\": \"${CIRCLE_TAG}\"\,/g" > package.json.new
            cat package.json.new > package.json
            rm package.json.new
      - run:
          name: Install node dependencies and Run build
          command: |
            cd app
            npm ci
            APP_VERSION=${CIRCLE_TAG} npm run build

Did you look at the resources in the Circle run? Maybe you’re running out of resources.

What does the build script in your project’s package.json do?

@wyardley, Wow! That was it… thank you very much. The build job didn’t have enough resources so it was getting killed.

1 Like

Depending at what exactly is happening, there may be some options other than just bumping the container resource class. For example, if the job is running out of memory, you may want to see if setting a value for --max-old-space-size in NODE_OPTIONS in the job that lines up with the amount of memory available in the container you’re using helps.

1 Like

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