next.js: jest-worker breaks building the project with "write EPIPE" error on macOS
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 21
- Comments: 15 (8 by maintainers)
This option in
next.config.js
seems to resolve the issue for us:It affects how
new Worker
fromjest-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:Specifically for jest-worker, it sets
numWorkers
in jest-worker here: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 asnumWorkers
. Forexperimental.cpus
, I can use the values 1, 2 and 3 for the build to succeed ✅. 4 and above lead to that EPIPE error 🚫.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)
Downgrading to version 10.2.3 solves the problem.
And yes, we’re on yarn 2 and PnP.
Just want to report that we had to give up on PnP, unfortunately 😕. There is something quite strange going on between Next.js, webpack, Yarn PnP and who-knows-what. This is a cross-post from our internal issue:
After avoiding the EPIPE error, builds started showing PnP errors like this:
I originally started dealing with those one by one – either installing it to our
package.json
files or adding them to.yarnrc.yml
but then I stopped and explored this specific “error” coming fromnode-fetch
.Optional peer dependencies, PnP and webpack
node-fetch has this in their compiled output:
That’s a correct way to try to load an optional peerDependency, and plain Node.js + Yarn PnP don’t have any problem with that: try creating a small project with
index.js
and a single dependency onnode-fetch
, this source code:and run it with
yarn node index.js
. It will work fine because PnP will throw an error inside a try/catch block, which will be swallowed by that try/catch and everything will work fine:However, when run via webpack, this fails, so it’s for further exploration in [internal issue].
BTW, by default,
next build
in both apps will fail with the error above. I also tried adding this to.yarnrc.yml
:Then it fails with a different error:
I still think this isn’t right – it’s an optional peer dependency so it shouldn’t be required to be provided by one of its ancestors.
Loose mode as a workaround
Added in [commit hash],
packages
now use loose mode.Build now passes but generates a lot of warnings:
These warnings can be silenced with
PNP_DEBUG_LEVEL=0
in Yarn 3 (we’re currently on 2.4.1) but better would be to find out why we’re seeing failed webpack builds on a perfectly valid code.Another strange thing is that trying to use webpack 4 produces very different output from webpack 5, about which I’ve posted https://github.com/vercel/next.js/discussions/27045.
All in all, Next.js 11 + Yarn PnP seems quite broken at this point.
We’ve been fighting this as well as part of our attempt to upgrade to Next.js 11. We’re not entirely sure what’s causing it but some observations are:
packages
to “latest” and to usenext@v11.0.2-canary.7
, this seems to almost solve the issue – we see the EPIPE error much less after that but it still happens (I’d say about 10% chance; before, it was like 95%)..next
folder from a previous successful run,yarn build
will typically succeed. When I delete it (rm -rf .next
), I get EPIPE error again.jest-worker
to a newer version –"jest-worker": "27.0.6"
in theresolutions
field inpackage.json
– didn’t help.errno: -32
might be a clue but I don’t know what that is – I’ve seen EPIPE connected to memory leaks, ungracefully closed SSL connections and many other things…This is still happening to me on next@11.1.2 node v16.2.0 and yarn 3.0.0.
Is there anyone who can test my modified PR(https://github.com/vercel/next.js/pull/28420) ? I checked it in my local project, but I want to see if it works in other projects as well.
I don’t think this is limited to mac btw. I’m seeing this on Windows as well.