nx: Unit test fails with an upgrade (NX Running target "test" failed)

Initially errored as follows,

  ● Test suite failed to run

    The service is no longer running

      at ../../../../node_modules/esbuild-wasm/lib/main.js:1276:29
      at sendRequest (../../../../node_modules/esbuild-wasm/lib/main.js:625:14)
      at start (../../../../node_modules/esbuild-wasm/lib/main.js:1274:9)
      at ../../../../node_modules/esbuild-wasm/lib/main.js:1742:82

and then got below error with a bunch of tests failed,

NX   Running target "test" failed
   Tasks not run because their dependencies failed or --nx-bail=true

The failed jobs never attempted to run and simply fails. it’s happening only on the GitLab pipelines!.

is there anything changed on the affected:test that can cause this failure?

Can someone please advise on this?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 22 (11 by maintainers)

Most upvoted comments

I am affected by this too… tests all running locally but in Gitlab CI environment some run and some fail with an error similar to the original post:

  ● Test suite failed to run
    The service was stopped
      at ../../../../../node_modules/jest-preset-angular/node_modules/esbuild-wasm/lib/main.js:1340:29

Since update from Nx 13 to 14.

So did some more debugging today, this looks to be related to esbuild process getting killed via host system due to resource limits.

I did some investigation via nrwl/nx-examples/pull/209 and was able to get the error of esbuild trying to write to a close pipe
[products       ] fatal error: too many writes on closed pipe
[products       ]
[products       ] goroutine 6 [running]:
[products       ] runtime.throw({0x87f5f[products       ] , 0x1e})
[products       ] 	/usr/local/go/src/runtime/panic.go:1198 +0x7 fp=0x1e7dee0 sp=0x1e7deb8 pc=0x12000007
[products       ] os.sigpipe()
[products       ] 	/usr/local/go/src/runtime/os_js.go:143 +0x2 fp=0x1e7def8 sp=0x1e7dee0 pc=0x137c0002
[products       ] os.epipecheck(...)
[products       ] 	/usr/local/go/src/os/file_unix.go[products       ] :196
[products       ] os.(*File).Write(0x40c020, {0x1d29a80, 0x21, 0x40})
[products       ] 	/usr/local/go/src/os/file.go:184 +0x25 fp=0x1e7df80 sp=0x1e7def8 pc=0x15b80025
[products       ] main.runService.func1(0x40f950)
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:114 +0xa fp=0x1e7dfd8 sp=0x1e7df80 pc=0x1da4000a
[products       ] runtime.goexit()
[products       ] 	/usr/local/go/src/runtime/asm_wasm.s:431 +0x1 fp=0x1e7dfe0 sp=0x1e7dfd8 pc=0x13d10001
[products       ] created by main.runService
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:108 +0xe
[products       ]
[products       ] goroutine 1 [chan receive]:
[products       ] syscall.fsCall({0x7af68, 0x4}, {0x461b98, 0x5, 0x5})
[products       ] 	/usr/local/go/src/syscall/fs_js.go:521 +0x13
[products       ] syscall.Read(0x0, {0x4c8000, 0x4000, 0x4000})
[products       ] 	/usr/local/go/src/syscall/fs_js.go:389 +0xc
[products       ] internal/poll.ignoringEINTRIO(...)
[products       ] 	/usr/local/go/src/internal/poll/fd_unix.go:582
[products       ] internal/poll.(*FD).Read(0x42c060, {0x4c8000, 0x4000, 0x4000})
[products       ] 	/usr/local/go/src/internal/poll/fd_unix.go:163 +0x4c
[products       ] os.(*File).read(...)
[products       ] 	/usr/local/go/src/os/file_posix.go:32
[products       ] os.(*File).Read(0x40c018, {0x4c8000, 0x4000, 0x4000})
[products       ] 	/usr/local/go/src/os/file.go:119 +0x10
[products       ] main.runService(0x1)
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:141[products       ]  +0x23
[products       ] main.main()
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/main.go:204 +0x8
[products       ]
[products       ] goroutine 7 [waiting]:
[products       ] runtime.gopark(0x0, 0x0, 0x0, 0x0, 0x1)
[products       ] 	/usr/local/go/src/runtime/proc.go:366 +0x27
[products       ] runtime.handleEvent()
[products       ] 	/usr/local/go/src/runtime/lock_js.go:250 +0x1b
[products       ] runtime.goexit()
[products       ] 	/usr/local/go/src/runtime/asm_wasm.s:431 +0x1
[products       ]
[products       ] goroutine 8 [chan receive]:
[products       ] main.(*serviceType).sendRequest(0x40f950, {0x3d300, 0x15e4b70})
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:203 +0xe
[products       ] main.runService.func2(0x40f950)
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:132 +0x3
[products       ] created by main.runService
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:129 +0x1e
[products       ]
[products       ] goroutine 9 [chan receive]:
[products       ] syscall.fsCall({0x7af08, 0x4}, {0x4db618, 0x3, 0x3})
[products       ] 	/usr/local/go/src/syscall/fs_js.go:521 +0x13
[products       ] syscall.Open({0x16cc180, 0x52}, 0x241, 0x1a4)
[products       ] 	/usr/local/go/src/syscall/fs_js.go:87 +0x1c
[products       ] os.openFileNolog({0x16cc180, 0x52}, 0x241, 0x1a4)
[products       ] 	/usr/local/go/src/os/file_unix.go:217 +0x14
[products       ] os.OpenFile({0x16cc180, 0x52}, 0x241, 0x1a4)
[products       ] 	/usr/local/go/src/os/file.go:338 +0x3
[products       ] os.WriteFile({0x16cc180, 0x52}, {0x2e78000, 0x8b739[products       ] , [products       ] 0x8b739}, 0x1a4)
[products       ] 	/usr/local/go/src/os/file.go:714 +0x2
[products       ] io/ioutil.WriteFile(...)
[products       ] 	/usr/local/go/src/io/ioutil/ioutil.go:46
[products       ] main.(*serviceType).handleTransformRequest(0x40f950, 0x0, 0x40fa40)
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:948 +0x2a[products       ]
[products       ] main.(*serviceType).handleIncomingPacket(0x40f950, {0x4ce000, 0x17f, 0x180})
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:236 +0x27
[products       ] main.runService.func3(0x40f950, {0x4ce000, 0x17f, 0x180})
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go[products       ] :163 +0x2
[products       ] created by main.runService
[products       ] 	/Users/evan/dev/esbuild/cmd/esbuild/service.go:162 +0x3a
[...ts-home-page]  FAIL   products-home-page  libs/products/home-page/src/lib/home-page/home-page.component.spec.ts
[...ts-home-page]   ● Test suite failed to run
[...ts-home-page]
[...ts-home-page]     The service was stopped
[...ts-home-page]
[...ts-home-page]       at ../../../node_modules/esbuild-wasm/lib/main.js:1344:29
[...ts-home-page]       at ../../../node_modules/esbuild-wasm/lib/main.js:640:9
[...ts-home-page]       at Socket.afterClose (../../../node_modules/esbuild-wasm/lib/main.js:617:7)
[...ts-home-page]
[...ts-home-page] in esbuild-wasm
[...ts-home-page] wasm-sendRequest { isClosed: false }
[...ts-home-page] wasm-afterClose { isClosed: false }
[...roduct-state]  FAIL   shared-product-state  libs/shared/product/state/src/lib/+state/products.selectors.spec.ts
[...roduct-state]   ● Test suite failed to run
[...roduct-state]
[...roduct-state]     The service was stopped
[...roduct-state]
[...roduct-state]       at ../../../../node_modules/esbuild-wasm/lib/main.js:1344:29
[...roduct-state]       at ../../../../node_modules/esbuild-wasm/lib/main.js:640:9
[...roduct-state]       at Socket.afterClose (../../../../node_modules/esbuild-wasm/lib/main.js:617:7)
[...roduct-state]
[...roduct-state] in esbuild-wasm
[...roduct-state] wasm-sendRequest { isClosed: false }
[...roduct-state] wasm-afterClose { isClosed: false }
[...roduct-state]  FAIL   shared-product-state  libs/shared/product/state/src/lib/+state/products.reducer.spec.ts
[...roduct-state]   ● Test suite failed to run
[...roduct-state]
[...roduct-state]     The service was stopped
[...roduct-state]
[...roduct-state]       at ../../../../node_modules/esbuild-wasm/lib/main.js:1344:29
[...roduct-state]       at ../../../../node_modules/esbuild-wasm/lib/main.js:640:9
[...roduct-state]       at Socket.afterClose (../../../../node_modules/esbuild-wasm/lib/main.js:617:7)

as for the fix here, I’m not 100% sure nx can do much. Some things to try is to lower the # of parallel threads running via --parallel flag and using the -runInBand flag when running in CI, Other wise Jest will spin up worker threads that include running the esbuild transformer. You can also try bumping the memory on your CI agents.

Now as to why the native esbuild binary isn’t able to run I’m not sure. There could be various reasons why esbuild native isn’t able to run like anti-virus incorrectly flagging it

jest-preset-angular falls back to esbuild-wasm if it cannot load esbuild, like angular. so that’s why it’s present, to begin with.

I would be interested if y’all could try some of the suggestions of lower the parallelism of nx and jest tests and seeing if the tests go away also checking if increasing the CI providers memory helps in any way.

only real change to jest has been how the default preset has to be imported. which is by default in your root jest.preset.js file, but you could be using it in other places. the v14.1.5 migration should have taken care of this for you. also, the output from running nx report would be a helpful place to start for debugging.

- const nxPreset = require('@nrwl/jest/preset');
+ const nxPreset = require('@nrwl/jest/preset').default;

for those coming across this issue, the (sort of) root cause was from a jest-preset-angular version missmatch. so when trying to check for esbuild it was throwing an error causing it to always fallback to esbuild-wasm. with the jest 28 support (#10857) the correct versions are synced back and should go away once migrating.

@barbados-clemens running with --parallel=1 worked for me, thanks!

@dean-g goal is to get the PR merged for Jest 28 this week, I have a few things with cypress 10 to finish first.