next-on-pages
next-on-pages copied to clipboard
[🐛 Bug]: "spawn npx ENOENT" error trying to run npx @cloudflare/next-on-pages on Windows
next-on-pages environment related information
System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Memory: 32 GB
Shell: C:\Program Files\Git\usr\bin\bash.exe
Package Manager Used: npm (10.2.3)
Relevant Packages:
@cloudflare/next-on-pages: 1.7.0
vercel: N/A
next: 14.0.5-canary.5
Description
The command npx @cloudflare/next-on-pages
fails with the following error:
⚡️ @cloudflare/next-on-pages CLI v.1.7.0
⚡️ Warning: It seems like you're on a Windows system, the Vercel CLI (run by @cloudflare/next-on-pages
⚡️ to build your application) seems not to work reliably on Windows so if you experience issues during
⚡️ the build process please try switching to a different operating system or running
⚡️ @cloudflare/next-on-pages under the Windows Subsystem for Linux
⚡️ Detected Package Manager: npm (10.2.3)
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
node:events:492
throw er; // Unhandled 'error' event
^
Error: spawn npx ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn npx',
path: 'npx',
spawnargs: [ 'vercel', 'build' ]
}
Node.js v20.10.0
This may or may not be related, but the command fails on both Powershell and WSL with a different error since 1.7.0:
⚡️ @cloudflare/next-on-pages CLI v.1.7.0
⚡️ Warning: It seems like you're on a Windows system, the Vercel CLI (run by @cloudflare/next-on-pages
⚡️ to build your application) seems not to work reliably on Windows so if you experience issues during
⚡️ the build process please try switching to a different operating system or running
⚡️ @cloudflare/next-on-pages under the Windows Subsystem for Linux
EXIT WHEN NOT EXPECTED
SHELLAC COMMAND FAILED!
Executing: npm --version in D:\Documents\Work\Admin
STDOUT:
The handle is invalid.
STDERR:
⚡️ Watch mode unexpected error: [object Object]
Reproduction
Run npx @cloudflare/next-on-pages
on Windows with Git Bash
Pages Deployment Method
None
Pages Deployment ID
No response
Additional Information
The happens since next-on-pages 1.7.0. I also tested this on 1.8.2. Version 1.6.3 is working fine.
There has been a similar issue in the past, which was fixed: https://github.com/cloudflare/next-on-pages/pull/96
Same issue
I figured out, using the home directory in WSL works, but not the windows drives. And node/npm need to be installed via WSL too, otherwise Windows is using the Windows installation.
I was having this problem when executing npm run preview which executes npm run pages:build && wrangler pages dev. For a moment I forked this project and used cross-spawn which solved a lot of problems executing commands on Windows via spawn. In addition, I added cross-env so that the setting of environment variables in the NPM scripts worked and then used shx so that the Linux commands rm -rf and cp worked as well.
However, I ran into further issues where it was trying to execute a bash shell and failing which I believe was related to package-manager-manager trying to execute npx. To get around this I executed npm run preview using Git Bash which then worked but ultimately lead me to another error which looks to be the fault of the Vercel CLI.
By all means, I am a huge Linux fan but my current development machine is running Windows. I know I could use WSL or perhaps create a VirtualBox VM running Linux but ideally I'd like everything to work natively on my current OS for performance reasons. I'm sure at some point the Vercel CLI will get better on Windows but for now it's definitely a non-starter.
Hopefully this information is helpful. Cheers.
Same issue please look into this
Still running on this issue with version 1.11.3
I replaced Windows with Linux on my development machine and the problem disappeared. Linux FTW
@danieleagle ikr this issue is only with windows.
Bun worked for me. Just run bunx @cloudflare/next-on-pages
as admin
Bun worked for me. Just run
bunx @cloudflare/next-on-pages
as admin
It didn't work for me using bunx @cloudflare/next-on-pages
😢
If anyone still getting this error, here's how i fixed it:
- Install WSL if you don't have it already.
- Open a WSL console from windows (just type WSL in Windows Search and it should pop up).
- Follow this tutorial to install nvm, npm and node in WSL.
- From your project folder, open a WSL console:
- And from this new console, you will be able to run the build, preview and deploy commands without errors.