How to Resolve Error: spawn pnpx ENOENT in Cloudflare
Sushil Ale
Product Focused Engineer | Experienced Java Software Engineer | FullStack Java Developer | SPR
or options to deploy my static site generated with JS framework for free. I have created a sample project with?Next.js?which is a React framework developed by?Vercel?and comes with many features. Among many options available I wanted to try?Cloudflare?to deploy it. You can also deploy your project in Vercel platform for free.
When I was trying to deploy project into Cloudflare I faced with this error
Error: spawn pnpx ENOEN
at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:485:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
at onErrorNT (node:internal/child_process:485:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn pnpx',
path: 'pnpx',
spawnargs: [ 'next-on-pages-vercel-cli', 'build' ]
We need to use?@cloudflare/next-on-pages cli tools to deploy NextJS project into cloudfare. I came across with an?issue?already created on github and it helped me to resolve my issue.
The script that we use to build NextJs project on cloudflare is
npx @cloudflare/next-on-pages@1
By default Cloudflare provides?npm?to build project. When you manage dependency using new cli?pnpm?then it has two?lock?files?package-lock.json?and?pnpm-lock.json?in your project. You can remove?package-lock.json?file if you are using?pnpm?to build your project. Since we have?pnpm-lock.json?file that has updated records of our dependencies?npm?doesn’t understand it and throw the above error.
To fix this error we need to add?pnpm?cli as dev dependency. To add?pnpm?as dev dependency you can use any of the following commands:
npm i -D pnpm
pnpm i -D pnpm
Reference: Medium Article