question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
adam-marshallcommented, Jun 24, 2022

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.

3reactions
barbados-clemenscommented, Jun 24, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NX workspace - angular 14 - jest not working - Stack Overflow
5 . Running npm update succeeds now. But running the unit tests npm run nx run-many -- --target=test --projects= ...
Read more >
nrwl-nx/community - Gitter
Hi, I'm trying to run affected:test but I'm getting errors: NX ERROR Running target "test" for affected projects failed . There is list...
Read more >
@nrwl/jest:jest | Nx
Update snapshots running with --update-snapshot or -u for short. nx test my-project -u ... Exit the test suite immediately after n number of...
Read more >
Unit test reports - GitLab Docs
If the tests fail, the pipeline fails and users get notified. The person that works on the merge request has to check the...
Read more >
nx jest unexpected token 'export' - You.com | The AI Search ...
I use Jest to create and run the unit test used in my monorepo. Problem. When I run jest, on some test it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found