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.

jest-worker breaks building the project with "write EPIPE" error on macOS

See original GitHub issue

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

16.4.2

What browser are you using?

Firefox

What operating system are you using?

macOs Big Sur 11.4 (MacBook Pro 15" 2017)

How are you deploying your application?

next build

Describe the Bug

I’ve decided to move my project on to next@11.0.1, using macOS for development. When i try building it, i get the following lines:

info  - Loaded env from /Users/brrrrrr/.env
(node:99496) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
info  - Checking validity of types
info  - Creating an optimized production build .node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at ChildProcess.target._send (node:internal/child_process:849:20)
    at ChildProcess.target.send (node:internal/child_process:722:19)
    at ChildProcessWorker.initialize (/Users/brrrrrr/.yarn/cache/jest-worker-npm-27.0.6-83200713fc-8d7ab8cdf6.zip/node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:11)
    at ChildProcessWorker._onExit (/Users/brrrrrr/.yarn/cache/jest-worker-npm-27.0.6-83200713fc-8d7ab8cdf6.zip/node_modules/jest-worker/build/workers/ChildProcessWorker.js:277:12)
    at ChildProcess.emit (node:events:394:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
Emitted 'error' event on ChildProcess instance at:
    at node:internal/child_process:853:39
    at processTicksAndRejections (node:internal/process/task_queues:78:11) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

At some point, the error was gone, but i cannot reproduce the steps necessary to completely fix the issue. This issue is related to macOS and nextjs >11 versions only as this error doesn’t pop up on other machines/versions. Related: This project uses the pnp packaging system from yarn version berry

Expected Behavior

The project should build.

To Reproduce

Calling next build on macOS with next@11

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:21
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
borekbcommented, Jul 9, 2021

This option in next.config.js seems to resolve the issue for us:

module.exports = {
  experimental: {
    cpus: 1,
  },
};

It affects how new Worker from jest-worker is created:

https://github.com/vercel/next.js/blob/d60c95cb57497396d534eb8dd6fce9a192fc22fe/packages/next/build/index.ts#L675

experimental.cpus is also used for other things like setting the parallelism for webpack build, see e.g. this full-text search:

Screen Shot 2021-07-09 at 12 07 24

Specifically for jest-worker, it sets numWorkers in jest-worker here:

const workerPoolOptions: WorkerPoolOptions = {
  numWorkers: this._options.numWorkers ?? Math.max(cpus().length - 1, 1),
  //...
};

On my machine which is MBP 16’’ 2019 with a 6-core Intel i7, cpus().length is 12 so jest-worker would then use 11 as numWorkers. For experimental.cpus, I can use the values 1, 2 and 3 for the build to succeed ✅. 4 and above lead to that EPIPE error 🚫.

5reactions
bhoodreamcommented, Jul 9, 2021

The same problem! My build is running in docker and periodically crashes with this error!

Next.js: 11.0.1 Node.js: 14.17.3 Yarn: 2.4.2 (PnP)

events.js:352
#9 98.36       throw er; // Unhandled 'error' event
#9 98.36       ^
#9 98.36 
#9 98.36 Error: write EPIPE
#9 98.36     at ChildProcess.target._send (internal/child_process.js:839:20)
#9 98.36     at ChildProcess.target.send (internal/child_process.js:710:19)
#9 98.36     at ChildProcessWorker.initialize (/app/.yarn/cache/jest-worker-npm-27.0.0-next.5-6f53fab806-7564f4c78c.zip/node_modules/jest-worker/build/workers/ChildProcessWorker.js:181:11)
#9 98.36     at ChildProcessWorker._onExit (/app/.yarn/cache/jest-worker-npm-27.0.0-next.5-6f53fab806-7564f4c78c.zip/node_modules/jest-worker/build/workers/ChildProcessWorker.js:275:12)
#9 98.36     at ChildProcess.emit (events.js:375:28)
#9 98.36     at ChildProcess.emit (domain.js:470:12)
#9 98.36     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
#9 98.36 Emitted 'error' event on ChildProcess instance at:
#9 98.36     at internal/child_process.js:843:39
#9 98.36     at processTicksAndRejections (internal/process/task_queues.js:77:11) {
#9 98.36   errno: -32,
#9 98.36   code: 'EPIPE',
#9 98.36   syscall: 'write'
#9 98.36 }

Downgrading to version 10.2.3 solves the problem.

And yes, we’re on yarn 2 and PnP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

write EPIPE when using ChildProcessWorker.js #10144 - GitHub
doWork (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:56:12) Emitted 'error' event at: at process.nextTick (internal/child_process.js: ...
Read more >
events.js:288 Error: write EPIPE when executing tests with Jest
It turns out that by changing some libraries in package.json the error dissapears: Before (KO): "babel-jest": "^24.9.0", "jest": "^26.0.1",.
Read more >
80% of the time build fails with Error: write EPIPE error
Building a JavaScript application using Create React App (yarn build) fails in ~80% of the time with the following error: Error: write EPIPE...
Read more >
Gatsby Changelog | 5.3.0
By using a new <Slice /> React component in combination with a src/slices directory or createSlice API for common UI features, Gatsby will...
Read more >
ts-node-dev - Bountysource
(node:10732) Warning: To load an ES module, set "type": "module" in the ... -example/node_modules/jest-worker/build/workers/ChildProcessWorker.js:264:15) at ...
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