nx: Jest & lint fails with the following ERROR: NX ERROR spawn E2BIG

Both my jest & lint fails with the following ERROR: NX ERROR spawn E2BIG

this is happening only on the CI pipeline. but the same works well in my local machine.

$ yarn affected:test 

yarn run v1.22.5
$ ./node_modules/.bin/nx affected:test --base=origin/test-code --parallel --detectOpenHandles --forceExit
>  NX   ERROR  spawn E2BIG
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 20 (3 by maintainers)

Most upvoted comments

OK. After some debugging I was able to resolve the issue in our repo. I’ll try to explain the solution, hopefully its useful for others as well.

Also: Thank you for building NX! It’s an awesome tool and we love using it.

Our setup:

1. We use cypress, and specify cypress cache folder like:

variables:
  CYPRESS_CACHE_FOLDER: '$CI_PROJECT_DIR/cache/Cypress'

2. We specify a cache object to reuse among jobs:

.cache_deps: &cache_deps
  key:
    files:
      - yarn.lock
  paths:
    - cache/Cypress
    - node_modules

3. We have an ‘install’ job.

install:
  image: node:lts-slim
  cache:
    <<: *cache_deps
    policy: push
  script:
    - yarn install --frozen-lockfile

Note: cypress cache-folder amounts to almost 26.000 (!) files.

4. We have a ‘lint’ job.

lint:
  image: node:lts
  cache:
    <<: *cache_deps
    policy: pull
  script:
    - npx nx affected:lint --base=origin/master

Result:

$ npx nx affected:lint --base=origin/master
>  NX   ERROR  spawn E2BIG

The solution:

Cypress cache was adding ~26.000 files, which are all checked by the affected command, causing it to fail. Adding /cache (our custom cypress cache location) to .gitignore makes NX ignore all of these files.

The affected:lint command now run smoothly again for us.

Did a git status before the crash and found out that I had .pnpm-store not added to .gitignore… fixed ^^

Yep I am facing this is an issue also with freshly apps workspace and adding new node app using @nrwl/node generator

yarn run v1.22.17
$ nx serve

 >  NX   spawn E2BIG


error Command failed with exit code 1.

This is likely a real issue. We’ll investigate it.

This is happening to me too, using GitLab’s Auto DevOps.

When running /bin/herokuish buildpack test on the test job, it fails with:

> nx run-many --all --target=test
 >  NX   spawn E2BIG

nx version: 13.8.0

Downgrading to 13.4.4 fixes the issue.

Thanks a lot, @Jeffrey-Zutt. that worked for me!