[Bug?]: Error: Dynamic require of "util" is not supported
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
I've tried on both node 18.8.2 and 20.8.1, uninstalling nodejs in between to try to clear it out.
I run corepack enable. Then I try to set the version to anything and it fails with Error: Dynamic require of "util" is not supported
yarn set version berry
yarn set version latest
yarn set version 3.6.4
yarn set version 2
Stack Trace
C:\Users\joeja>yarn dlx -q envinfo --preset jest
file:///C:/Users/joeja/AppData/Local/node/corepack/yarn/3.6.3/yarn.js:4
(()=>{var Dge=Object.create;var lS=Object.defineProperty;var kge=Object.getOwnPropertyDescriptor;var Rge=Object.getOwnPropertyNames;var Fge=Object.getPrototypeOf,Nge=Object.prototype.hasOwnProperty;var J=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+r+'" is not supported')});var Tge=(r,e)=>()=>(r&&(e=r(r=0)),e);var w=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ut=(r,e)=>{for(var t in e)lS(r,t,{get:e[t],enumerable:!0})},Lge=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Rge(e))!Nge.call(r,n)&&n!==t&&lS(r,n,{get:()=>e[n],enumerable:!(i=kge(e,n))||i.enumerable});return r};var Pe=(r,e,t)=>(t=r!=null?Dge(Fge(r)):{},Lge(e||!r||!r.__esModule?lS(t,"default",{value:r,enumerable:!0}):t,r));var PK=w((z7e,xK)=>{xK.exports=vK;vK.sync=ife;var QK=J("fs");function rfe(r,e){var t=e.pathExt!==void 0?e.pathExt:process.env.PATHEXT;if(!t||(t=t.split(";"),t.indexOf("")!==-1))return!0;for(var i=0;i<t.length;i++){var n=t[i].toLowerCase();if(n&&r.substr(-n.length).toLowerCase()===n)return!0}return!1}function SK(r,e,t){return!r.isSymbolicLink()&&!r.isFile()?!1:rfe(e,t)}function vK(r,e,t){QK.stat(r,function(i,n){t(i,i?!1:SK(n,r,e))})}function ife(r,e){return SK(QK.statSync(r),r,e)}});var NK=w((V7e,FK)=>{FK.exports=kK;kK.sync=nfe;var DK=J("fs");function kK(r,e,t){DK.stat(r,function(i,n){t(i,i?!1:RK(n,e))})}function nfe(r,e){return RK(DK.statSync(r),e)}function RK(r,e){return r.isFile()&&sfe(r,e)}function sfe(r,e){var t=r.mode,i=r.uid,n=r.gid,s=e.uid!==void 0?e.uid:process.getuid&&process.getuid(),o=e.gid!==void 0?e.gid:process.getgid&&process.getgid(),a=parseInt("100",8),l=parseInt("010",8),c=parseInt("001",8),u=a|l,g=t&c||t&l&&n===o||t&a&&i===s||t&u&&s===0;return g}});var LK=w((Z7e,TK)=>{var X7e=J("fs"),lI;process.platform==="win32"||global.TESTING_WINDOWS?lI=PK():lI=NK();TK.exports=SS;SS.sync=ofe;function SS(r,e,t){if(typeof e=="function"&&(t=e,e={}),!t){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(i,n){SS(r,e||{},function(s,o){s?n(s):i(o)})})}lI(r,e||{},function(i,n){i&&(i.code==="EACCES"||e&&e.ignoreErrors)&&(i=null,n=!1),t(i,n)})}function ofe(r,e){try{return lI.sync(r,e||{})}catch(t){if(e&&e.ignoreErrors||t.code==="EACCES")return!1;throw t}}});var YK=w((_7e,GK)=>{var Dg=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",MK=J("path"),afe=Dg?";":":",OK=LK(),KK=r=>Object.assign(new Error(`not found: ${r}`),{code:"ENOENT"}),UK=(r,e)=>{let t=e.colon||afe,i=r.match(/\//)||Dg&&r.match(/\\/)?[""]:[...Dg?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(t)],n=Dg?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",s=Dg?n.split(t):[""];return Dg&&r.indexOf(".")!==-1&&s[0]!==""&&s.unshift(""),{pathEnv:i,pathExt:s,pathExtExe:n}},HK=(r,e,t)=>{typeof e=="function"&&(t=e,e={}),e||(e={});let{pathEnv:i,pathExt:n,pathExtExe:s}=UK(r,e),o=[],a=c=>new Promise((u,g)=>{if(c===i.length)return e.all&&o.length?u(o):g(KK(r));let f=i[c],h=/^".*"$/.test(f)?f.slice(1,-1):f,p=MK.join(h,r),C=!h&&/^\.[\\\/]/.test(r)?r.slice(0,2)+p:p;u(l(C,c,0))}),l=(c,u,g)=>new Promise((f,h)=>{if(g===n.length)return f(a(u+1));let p=n[g];OK(c+p,{pathExt:s},(C,y)=>{if(!C&&y)if(e.all)o.push(c+p);else return f(c+p);return f(l(c,u,g+1))})});return t?a(0).then(c=>t(null,c),t):a(0)},Afe=(r,e)=>{e=e||{};let{pathEnv:t,pathExt:i,pathExtExe:n}=UK(r,e),s=[];for(let o=0;o<t.length;o++){let a=t[o],l=/^".*"$/.test(a)?a.slice(1,-1):a,c=MK.join(l,r),u=!l&&/^\.[\\\/]/.test(r)?r.slice(0,2)+c:c;for(let g=0;g<i.length;g++){let f=u+i[g];try{if(OK.sync(f,{pathExt:n}))if(e.all)s.push(f);else return f}catch{}}}if(e.all&&s.length)return s;if(e.nothrow)return null;throw KK(r)};GK.exports=HK;HK.sync=Afe});var qK=w(($7e,vS)=>{"use strict";var jK=(r={})=>{let e=r.env||process.env;return(r.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(i=>i.toUpperCase()==="PATH")||"Path"};vS.exports=jK;vS.exports.default=jK});var VK=w((eZe,zK)=>{"use strict";var JK=J("path"),lfe=YK(),cfe=qK();function WK(r,e){let t=r.options.env||process.env,i=process.cwd(),n=r.options.cwd!=null,s=n&&process.chdir!==void 0&&!process.chdir.disabled;if(s)try{process.chdir(r.options.cwd)}catch{}let o;try{o=lfe.sync(r.command,{path:t[cfe({env:t})],pathExt:e?JK.delimiter:void 0})}catch{}finally{s&&process.chdir(i)}return o&&(o=JK.resolve(n?r.options.cwd:"",o)),o}function ufe(r){return WK(r)||WK(r,!0)}zK.exports=ufe});var XK=w((tZe,PS)=>{"use strict";var xS=/([()\][%!^"`<>&|;, *?])/g;function gfe(r){return r=r.replace(xS,"^$1"),r}function ffe(r,e){return r=`${r}`,r=r.replace(/(\\*)"/g,'$1$1\\"'),r=r.replace(/(\\*)$/,"$1$1"),r=`"${r}"`,r=r.replace(xS,"^$1"),e&&(r=r.replace(xS,"^$1")),r}PS.exports.command=gfe;PS.exports.argument=ffe});var _K=w((rZe,ZK)=>{"use strict";ZK.exports=/^#!(.*)/});var eU=w((iZe,$K)=>{"use strict";var hfe=_K();$K.exports=(r="")=>{let e=r.match(hfe);if(!e)return null;let[t,i]=e[0].replace(/#! ?/,"").split(" "),n=t.split("/").pop();return n==="env"?i:i?`${n} ${i}`:n}});var rU=w((nZe,tU)=>{"use strict";var DS=J("fs"),pfe=eU();function dfe(r){let t=Buffer.alloc(150),i;try{i=DS.openSync(r,"r"),DS.readSync(i,t,0,150,0),DS.closeSync(i)}catch{}return pfe(t.toString())}tU.exports=dfe});var oU=w((sZe,sU)=>{"use strict";var Cfe=J("path"),iU=VK(),nU=XK(),mfe=rU(),Efe=process.platform==="win32",Ife=/\.(?:com|exe)$/i,yfe=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function wfe(r){r.file=iU(r);let e=r.file&&mfe(r.file);return e?(r.args.unshift(r.file),r.command=e,iU(r)):r.file}function Bfe(r){if(!Efe)return r;let e=wfe(r),t=!Ife.test(e);if(r.options.forceShell||t){let i=yfe.test(e);r.command=Cfe.normalize(r.command),r.command=nU.command(r.command),r.args=r.args.map(s=>nU.argument(s,i));let n=[r.command].concat(r.args).join(" ");r.args=["/d","/s","/c",`"${n}"`],r.command=process.env.comspec||"cmd.exe",r.options.windowsVerbatimArguments=!0}return r}function bfe(r,e,t){e&&!Array.isArray(e)&&(t=e,e=null),e=e?e.slice(0):[],t=Object.assign({},t);let i={command:r,args:e,options:t,file:void 0,original:{command:r,args:e}};return t.shell?i:Bfe(i)}sU.exports=bfe});var lU=w((oZe,AU)=>{"use strict";var kS=process.platform==="win32";function RS(r,e){return Object.assign(new Error(`${e} ${r.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${r.command}`,path:r.command,spawnargs:r.args})}function Qfe(r,e){if(!kS)return;let t=r.emit;r.emit=function(i,n){if(i==="exit"){let s=aU(n,e,"spawn");if(s)return t.call(r,"error",s)}return t.apply(r,arguments)}}function aU(r,e){return kS&&r===1&&!e.file?RS(e.original,"spawn"):null}function Sfe(r,e){return kS&&r===1&&!e.file?RS(e.original,"spawnSync"):null}AU.exports={hookChildProcess:Qfe,verifyENOENT:aU,verifyENOENTSync:Sfe,notFoundError:RS}});var TS=w((aZe,kg)=>{"use strict";var cU=J("child_process"),FS=oU(),NS=lU();function uU(r,e,t){let i=FS(r,e,t),n=cU.spawn(i.command,i.args,i.options);return NS.hookChildProcess(n,i),n}function vfe(r,e,t){let i=FS(r,e,t),n=cU.spawnSync(i.command,i.args,i.options);return n.error=n.error||NS.verifyENOENTSync(n.status,i),n}kg.exports=uU;kg.exports.spawn=uU;kg.exports.sync=vfe;kg.exports._parse=FS;kg.exports._enoent=NS});var fU=w((AZe,gU)=>{"use strict";function xfe(r,e){function t(){this.constructor=r}t.prototype=e.prototype,r.prototype=new t}function Zl(r,e,t,i){this.message=r,this.expected=e,this.found=t,this.location=i,this.name="SyntaxError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,Zl)}xfe(Zl,Error);Zl.buildMessage=function(r,e){var t={literal:function(c){return'"'+n(c.text)+'"'},class:function(c){var u="",g;for(g=0;g<c.parts.length;g++)u+=c.parts[g]instanceof Array?s(c.parts[g][0])+"-"+s(c.parts[g][1]):s(c.parts[g]);return"["+(c.inverted?"^":"")+u+"]"},any:function(c){return"any character"},end:function(c){return"end of input"},other:function(c){return c.description}};function i(c){return c.charCodeAt(0).toString(16).toUpperCase()}function n(c){return c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+i(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+i(u)})}function s(c){return c.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(u){return"\\x0"+i(u)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(u){return"\\x"+i(u)})}function o(c){return t[c.type](c)}function a(c){var u=new Array(c.length),g,f;for(g=0;g<c.length;g++)u[g]=o(c[g]);if(u.sort(),u.length>0){for(g=1,f=1;g<u.length;g++)u[g-1]!==u[g]&&(u[f]=u[g],f++);u.length=f}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}function l(c){return c?'"'+n(c)+'"':"end of input"}return"Expected "+a(r)+" but "+l(e)+" found."};function Pfe(r,e){e=e!==void 0?e:{};var t={},i={Start:SA},n=SA,s=function(m){return m||[]},o=function(m,Q,N){return[{command:m,type:Q}].concat(N||[])},a=function(m,Q){return[{command:m,type:Q||";"}]},l=function(m){return m},c=";",u=me(";",!1),g="&",f=me("&",!1),h=function(m,Q){return Q?{chain:m,then:Q}:{chain:m}},p=function(m,Q){return{type:m,line:Q}},C="&&",y=me("&&",!1),B="||",v=me("||",!1),D=function(m,Q){return Q?{...m,then:Q}:m},T=function(m,Q){return{type:m,chain:Q}},H="|&",j=me("|&",!1),$="|",V=me("|",!1),W="=",_=me("=",!1),A=function(m,Q){return{name:m,args:[Q]}},Ae=function(m){return{name:m,args:[]}},ge="(",re=me("(",!1),M=")",F=me(")",!1),ue=function(m,Q){return{type:"subshell",subshell:m,args:Q}},pe="{",ke=me("{",!1),Fe="}",Ne=me("}",!1),oe=function(m,Q){return{type:"group",group:m,args:Q}},le=function(m,Q){return{type:"command",args:Q,envs:m}},Be=function(m){return{type:"envs",envs:m}},fe=function(m){return m},ae=function(m){return m},qe=/^[0-9]/,ne=Je([["0","9"]],!1,!1),Y=function(m,Q,N){return{type:"redirection",subtype:Q,fd:m!==null?parseInt(m):null,args:[N]}},he=">>",ie=me(">>",!1),de=">&",_e=me(">&",!1),Pt=">",It=me(">",!1),Mr="<<<",ii=me("<<<",!1),gi="<&",hr=me("<&",!1),fi="<",ni=me("<",!1),Ks=function(m){return{type:"argument",segments:[].concat(...m)}},pr=function(m){return m},Ii="$'",rs=me("$'",!1),fa="'",dA=me("'",!1),cg=function(m){return[{type:"text",text:m}]},is='""',CA=me('""',!1),ha=function(){return{type:"text",text:""}},wp='"',mA=me('"',!1),EA=function(m){return m},wr=function(m){return{type:"arithmetic",arithmetic:m,quoted:!0}},Tl=function(m){return{type:"shell",shell:m,quoted:!0}},ug=function(m){return{type:"variable",...m,quoted:!0}},yo=function(m){return{type:"text",text:m}},gg=function(m){return{type:"arithmetic",arithmetic:m,quoted:!1}},Bp=function(m){return{type:"shell",shell:m,quoted:!1}},bp=function(m){return{type:"variable",...m,quoted:!1}},vr=function(m){return{type:"glob",pattern:m}},se=/^[^']/,wo=Je(["'"],!0,!1),Fn=function(m){return m.join("")},fg=/^[^$"]/,bt=Je(["$",'"'],!0,!1),Ll=`\\
^
Error: Dynamic require of "util" is not supported
at file:///C:/Users/joeja/AppData/Local/node/corepack/yarn/3.6.3/yarn.js:4:393
at file:///C:/Users/joeja/AppData/Local/node/corepack/yarn/3.6.3/yarn.js:309:2848
at file:///C:/Users/joeja/AppData/Local/node/corepack/yarn/3.6.3/yarn.js:744:8770
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)
Node.js v20.8.1
C:\Users\joeja>yarn -v
1.22.19
To reproduce
N/A - Cant reproduce
Environment
Windows 11 Pro 22H2
Even running `yarn dlx -q envinfo --preset jest` gives me the same error of dynamic import so I cant get this information
Additional context
Did the update on my laptop and it worked fine there. I understand this may just be a weird issue with my windows install and I've been meaning to do a fresh install so it might just be time for that. Figured I'd post the issue in since 4.0 just released and figured it might be related.
Potentially related: https://github.com/evanw/esbuild/issues/2113
I just resolved this.
Someone in the discord suggested I may have a package.json in my users folder. After deleting that, I was able to set my version to berry but it also broke yarn. I couldn't run any yarn commands as it would just error out saying it couldnt find 1.22.19.
I uninstalled node and deleted all the following folders:
C:\Program Files (x86)\Nodejs
C:\Program Files\Nodejs
C:\Users\{User}\AppData\Roaming\npm
C:\Users\{User}\AppData\Roaming\npm-cache
C:\Users\{User}\.npmrc
C:\Users\{User}\package.json
C:\Users\{User}\package-lock.json
C:\Users\{User}\AppData\Local\Temp\npm-*
After reinstalling node, I enabled corepack, went into my project, set the version to berry and its all working again.
Thanks @jrj2211 , solve my problem. For me just remove C:\Users{User}\package.json C:\Users{User}\package-lock.json is enough.
But hard to find this answer, can you update this issue title with Error: Dynamic require of "util" is not supported for others to find here?
@naruto00fa Updated the title.
Interesting, I had originally also tried to just remove the C:\Users{User}\package-lock.json but still got the same error. For any future people finding this, I guess it would make sense to try that first, before completely wiping node.
@jrj2211 I'm getting this when type: module is defined in the package.json. Any idea why?
Even running yarn --version gives me this error. If I remove the type: module, then I can get the version, which is:
β yarn --version
4.0.2
I'm on Node 18.12.1 (Windows 11)
Edit: not sure why but this was failing because I also had main: index.js. With that removed and type: module present the yarn --version works as expeced (as well as other yarn commands).
The problem happens only for yarn 4. I've downgraded to yarn 3.2.4 and it's working fine π€·ββοΈ
I'm still facing this issue on Vercel. All versions >3.2.4 are all broken...
Still facing this issue when deploying using a Dockerfile
FROM node:20-alpine
# Yarn modern installation
RUN corepack enable
RUN yarn set version stable
# Move to working directory /build
WORKDIR /
# Copy the code into the container
COPY . .
# Install dependencies
RUN yarn install
# Export necessary ports
EXPOSE 8080
# Running the script that runs both the Go and NodeJS servers
CMD ["npm", "run", "prod:start"]
I have this problem under linux, too. I have created a separate user. For that user $HOME is the root of the JS-project. It has $HOME/package.js . My understanding here is that $HOME/package.js is the root cause. So I changed to root, performed corepack use yarn@*, changed back to that user, and chowned the files to the user. This workaround does function, but is still a workaround.
Stumbled upon this today, as well, on Alpine 3.19.
@wojtekmaj Maybe we should consider re-opening the issue (unless it's being tracked somewhere else)?
My problem was a package.json in my $HOME directory (which is a rather common thing to have in Dockerfile builder stages). Moving it to any other dir, made yarn work as expected.
~ $ pwd
/home/user
~ $ ls
app package.json public server
~ $ corepack install
Adding [email protected] to the cache...
~ $ yarn --version
file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:4
Error: Dynamic require of "util" is not supported
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:4:394
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:4:3572
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:4:478
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:9:45685
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:4:478
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:392:1509
at file:///home/user/.cache/node/corepack/v1/yarn/4.1.1/yarn.js:734:11937
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
~ $ node --version
v20.12.1
~ $ npm --version
10.2.5
~ $ corepack --version
0.28.0
Stumbled upon this after adding "type": "module" to my root package.json while using corepack deploying on Vercel.
The error is described in a discussion in their repo and was closed.
This is reproduced as simple as:
# Outer package.json, could be anywhere up from the project dir
touch package.json && echo "{\"type\":\"module\"}" >> package.json
mkdir test && cd test
# Project package.json
touch package.json && echo "{\"packageManager\": \"[email protected]\"}" >> package.json
nvm use 20 # being specific just in case
corepack enable
yarn install
Logging console.log('typeof require', typeof require) on the top of the ~/.cache/node/corepack/v1/yarn/3.8.4/yarn.js gives undefined in given setup, but function if outer json doesn't have "type": "module".
Having multiple package.jsons on the way up will resolve type to the topmost package.json.
@wojtekmaj This might be a corepack problem, but I didn't dig deeper.
I'm still facing this issue on Vercel. All versions
>3.2.4are all broken... @JounQin
I got around this by overriding the vercel install command to:
corepack use [email protected] && echo "yarnPath: ${HOME}/.cache/node/corepack/v1/yarn/4.3.1/yarn.js" >> .yarnrc.yml && yarn install
(change the yarn version to that desired)
@joezappie could you reopen this issue please, as many of us are still having this problem with the latest yarn / in Docker etc. and none of the proposed solutions seem to work
FWIW I worked around this issue by just committing the yarn release to the repo and redeploying to vercel. A bit janky but it works. YMMV.
@joezappie I put together a simple Docker repository with a small NodeJS project that reproduces the issue. There is no excessive package.json in the project anywhere so that's not the issue.
https://github.com/Supinic/test-corepack-yarn-esm
@adamreisnz @Supinic I've reopened the issue as it seems theres still some issues here past rogue package-lock.json files being in parent folders outside of the project. I don't use yarn for anything atm so its not a pressing issue for me, but hopefully someone on the yarn team can help out with this.
I did try your docker build file though and can confirm I get the util error as well.
To make it work I needed not only to modify install script (as per https://github.com/yarnpkg/berry/issues/5831#issuecomment-2364260390) but also remove ENABLE_EXPERIMENTAL_COREPACK once enabled.
I also have this problem and unfortunately no workaround above fixed it for me.
I might have some more infos, although no solution. I get this error when working with node on nixos. In a sandboxed .direnv environment. On nix, I have to modify corepacks env variables to make it work with a bash script below that I use as a shell hook:
you can see we sinply set env variables and enable corepack with a project-specific dir.
### ability to use modern yarn
# Put shims & downloaded package managers inside repo
# this helps with our new yarn version using corepack on nixos!
export COREPACK_HOME="$(pwd)/.corepack/home"
export PATH="$(pwd)/.corepack/bin:$PATH"
if [ ! -e "$(pwd)/.corepack/bin/yarn" ]; then
echo "[devShell] Generating Corepack shims β .corepack/bin"
mkdir -p "$(pwd)/.corepack/bin"
# --install-directory keeps writes out of /nix/store
corepack enable --install-directory="$(pwd)/.corepack/bin"
fi
what this means is:
we have the ".corepack" dir inside the project directory itself on the same level as the package.json (project "A")
now I have another project "B" where the package.json is in a subdir. like
interestingly in project "A" we get the error "Dynamic require of "util" is not supported" but in project B, where the .corepack directory is separated, everything works just fine! Not sure, if thats the issue.. but maybe it helps in narrowing down causes... I am still investigating if I can find more..
To make it work I needed not only to modify install script (as per #5831 (comment)) but also remove
ENABLE_EXPERIMENTAL_COREPACKonce enabled.
Thank u for saving my poor ass. @theblockstalk @luixo ! I guess it took you some hours to figure this out.
Here's what worked for me:
- ran:
yarn set version 4.8.1 --yarn-path # this added .yarn/releases/yarn-4.8.1.cjs file and modified .yarnrc.yml to point to it
- disabled
ENABLE_EXPERIMENTAL_COREPACKenv var
@naruto00fa Updated the title.
Interesting, I had originally also tried to just remove the
C:\Users{User}\package-lock.jsonbut still got the same error. For any future people finding this, I guess it would make sense to try that first, before completely wiping node.
Doing this worked for me!
After hours of debugging and trying all the solutions in this thread, the one that worked in the end was to ditch Yarn and switch to pnpm. Took 5 minutes to replace yarn, and everything worked right away βΊοΈ
My understanding from a cursory glance is that you install the project in the HOME folder, so scripts evaluated with the .js extension (which seems to be the case for the Corepack cached files) accidentally rely on type detection ?
If that's the case the fix is on Corepack, as files would need to be stored with the .cjs extension. Pnpm isn't impacted because they are distributed as a tarball (with a package.json and all), whereas Yarn is a single JavaScript file.
As a workaround, I imagine something like this might work:
echo '{"type": "commonjs"}' >> ~/.cache/node
Alternatively your project could be cloned in another folder than $HOME. Perhaps easier to do in Docker than those cloud providers.
hi, i encountered the same issue , running a parallel worker . wanted to try to delete the package-lock.json, but thought i would ask ai assistant using sonnet 4.5 before that, which resulted in another solution that works for me.
what is the package-lock.json file for? i might need to delete it because of an error: Error: Dynamic require of "util" is not supported at file:///home/runner/workspace/server/scheduler-worker.js:11:9 at node_modules/object-inspect/util.inspect.js (file:///home/runner/workspace/server/scheduler-worker.js:806:22) at __require2 (file:///home/runner/workspace/server/scheduler-worker.js:14:50) at node_modules/object-inspect/index.js (file:///home/runner/workspace/server/scheduler-worker.js:864:23) at __require2 (file:///home/runner/workspace/server/scheduler-worker.js:14:50) at node_modules/side-channel/index.js (file:///home/runner/workspace/server/scheduler-worker.js:1331:19) at __require2 (file:///home/runner/workspace/server/scheduler-worker.js:14:50) at node_modules/qs/lib/stringify.js (file:///home/runner/workspace/server/scheduler-worker.js:1675:26) at __require2 (file:///home/runner/workspace/server/scheduler-worker.js:14:50) at node_modules/qs/lib/index.js (file:///home/runner/workspace/server/scheduler-worker.js:2182:22)
unless you have a better idea that you can present to me, i found in a forum that it helped for some people. but i am unsure if it breaks something else deleting that file PS
Assistant 25 minutes ago Read 6 files The package-lock.json file is npm's lockfile that ensures consistent dependency versions across different installations. Deleting it won't solve your problem and will likely cause other issues by allowing dependency versions to drift.
The error you're seeing is actually about the worker thread bundling, not package-lock.json. The issue is that object-inspect (a deep dependency of qs) is trying to dynamically require the util module, but esbuild can't bundle dynamic requires properly.
Looking at your AGENTS.md documentation, you need to add util to the external modules list when rebuilding the worker. Here's the fix:
npx esbuild server/scheduler-worker.ts --bundle --platform=node --format=esm --outfile=server/scheduler-worker.js --external:ws --external:@neondatabase/serverless --external:drizzle-orm --external:stream --external:util --external:crypto --external:fs --external:path --external:url --external:qs
Run again The key changes:
Added --external:qs to prevent bundling the qs library (which is causing the util require issue) util is already in your external list, but qs needs to be external too since it's causing the dynamic require problem After running this command, restart your application. The worker thread should start successfully without falling back to the main thread scheduler.
Do not delete package-lock.json - it's not related to this error and removing it would only cause dependency management problems.