Error: Dynamic require of "util" is not supported

I’m getting the following error message: when using yarn 4.1.0

Error: Command "yarn install" exited with 1

Hey @josh-protectaico. This is very little info to work from. Can you share more error details and some more information about your project?

Yes, apologies. We’re using yarn 4.1.0 with corepack and our Vercel preview builds are immediately failing when running yarn install. The full error message is:

Error: Dynamic require of "util" is not supported
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:4:394
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:4:3572
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:4:478
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:9:45685
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:4:478
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:392:1509
    at file:///vercel/path0/.vercel/cache/corepack/home/v1/yarn/4.1.0/yarn.js:734:11937
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
Node.js v20.16.0
Error: Command "yarn install" exited with 1

We are using the ENABLE_EXPERIMENTAL_COREPACK flag and it hasn’t been an issue until today. The repo that is running into this issue is using the global instance of yarn here instead of an included binary.

This hasn’t been an issue in our other projects that use yarn 3.6.3 with an included binary.

Thanks for posting this update! I was able to dig up some information about Yarn v4 and can confirm that it is not officially supported on Vercel. That’s likely the reason for the Corepack error.

If you switch to an earlier version of Yarn, does that eliminate the error?

Switching to a different version of yarn didn’t fix the issue. I had to disable the ENABLE_EXPERIMENTAL_COREPACK flag for it to start working. This also required me to switch over to using a yarnPath in my .yarnrc file and add the corresponding yarn binary to the repo.

1 Like

I’m glad you found a solution! Thanks for letting us know what worked for you. :smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.