cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.17k stars 109 forks source link

[🐛 Bug]: "spawn npx ENOENT" error trying to run npx @cloudflare/next-on-pages on Windows #608

Open kmsomebody opened 6 months ago

kmsomebody commented 6 months ago

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

pvhieuit commented 5 months ago

Same issue

kmsomebody commented 5 months ago

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.

danieleagle commented 2 months ago

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.

ronitrajfr commented 1 month ago

Same issue please look into this

nicolaspapp commented 1 month ago

Still running on this issue with version 1.11.3

danieleagle commented 1 month ago

I replaced Windows with Linux on my development machine and the problem disappeared. Linux FTW

ronitrajfr commented 1 month ago

@danieleagle ikr this issue is only with windows.

flippyboi commented 4 weeks ago

Bun worked for me. Just run bunx @cloudflare/next-on-pages as admin