Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: npx @cloudflare/next-on-pages fails on windows #863

Open
1 task done
thomas-desmond opened this issue Aug 23, 2024 · 9 comments
Open
1 task done

[🐛 Bug]: npx @cloudflare/next-on-pages fails on windows #863

thomas-desmond opened this issue Aug 23, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@thomas-desmond
Copy link

next-on-pages environment related information

PS C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app> npx @cloudflare/next-on-pages --info
EXIT WHEN NOT EXPECTED

SHELLAC COMMAND FAILED!
Executing: npm --version in C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app

STDOUT:

STDERR:

/bin/bash: line 1: cd: C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app: No such file or directory

node:internal/process/promises:389
new UnhandledPromiseRejection(reason);
^

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#".
at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
at processPromiseRejections (node:internal/process/promises:470:17)
at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v20.16.0

Description

npx @cloudflare/next-on-pages fails on my Windows machine. At this point it feels like something is configured wrong on my machine but I have not come across documentation pointing me to what I should set up.

I have tried using the Windows Subsystem for Linux like the error for npm run page:build prompts me to do but there is no change in error when running in a Ubuntu terminal on Windows.

Reproduction

I created a brand new Next.js application with npm create cloudflare@latest my-next-app -- --framework=next.

I attempt to run npm run pages:build I get the following error.

/mnt/c/Users/tdesmond/Projects/cloudflare/temp/my-next-app$ npm run pages:build

> my-next-app@0.1.0 pages:build
> npx @cloudflare/next-on-pages

⚡️ @cloudflare/next-on-pages CLI v.1.13.2

⚡️ 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 C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app

STDOUT:



STDERR:

/bin/bash: line 1: cd: C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app: No such file or directory


⚡️ Unexpected error: {"retCode":1,"cmd":"npm --version","stdout":"","stderr":"/bin/bash: line 1: cd: C:\\Users\\tdesmond\\Projects\\cloudflare\\temp\\my-next-app: No such file or directory
⚡️ "}

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

No response

Would you like to help?

  • Would you like to help fixing this bug?

@thomas-desmond thomas-desmond added the bug Something isn't working label Aug 23, 2024
@irvinebroque
Copy link

do you see this when just building the same app without next-on-pages?

@thomas-desmond
Copy link
Author

npm run build passes. I deployed the app to Pages as well and it builds on Pages.

So definitely looking like a local setup issue. But I do not know what is missing locally.

@thomas-desmond
Copy link
Author

I got one step further but still failing. The original error is saying the directory doesn't exist. But because I'm in WSL the directory locations changes and has /mnt/ in front and is formatted differently. So I created a symbolic link from where the CLI was expecting my app to be (C:\Users\tdesmond\Projects\cloudflare\temp\my-next-app) to where it actually lives in WSL (/mnt/c/Users/tdesmond/Projects/cloudflare/temp/my-next-app)

I get further but still run into an error.

image

@danbrownuk
Copy link

danbrownuk commented Aug 25, 2024

I was able to get this to run by fudging a few lines in index.js to play nicely with WSL. I'm sure there's a better way but this seems to work for now...

Update Command to format cwd to WSL format (/mnt/ at start, flipping slashes and lowercasing drive letter, removing ':', replacing usage of {cwd} with {this.cwd} )
var Command = class { shell; cmd; cwd; interactive; exec; runningState; pipe_logs; exit_expected; retCode; promiseResolve; promiseReject; promise; timer; stdout; stderr; constructor({ cwd, shell, cmd, interactive, pipe_logs = false, exit_expected = false }) { this.shell = shell; this.cmd = cmd; this.cwd = '/mnt/' + cwd.split('\:')[0].toLowerCase() + cwd.split(':')[1].replace(/\\/g, '/'); this.interactive = interactive; this.exit_expected = exit_expected; this.exec = cd "${this.cwd}" &&
${this.cmd};echo END_OF_COMMAND[$?]_
;

Add shell: true to options of vercel build child process spawn
async function getVercelBuildChildProcess(pm, additionalArgs = []) { console.log("trying vercel") const spawnCmd = await pm.getRunExecStruct("vercel", { args: ["build", ...additionalArgs], download: "prefer-if-needed" }); console.log(spawnCmd); if (!spawnCmd) { throw new Error("Error: Failed to generate vercel build command"); } return (0, import_child_process2.spawn)(spawnCmd.cmd, spawnCmd.cmdArgs, {shell: true}); }

After making these tweaks (inside node_modules@cloudflare\next-on-pages\dist\index.js), run powershell/cmd prompt as Administrator and then the build should complete :)

@mackenly
Copy link
Contributor

I'm getting this issue, too. I worked around it by running in WSL Ubuntu. It seems to be Windows specific.

@thomas-desmond
Copy link
Author

Making the changes suggested by @danbrownuk I was able to get the npm run pages:build and npm run pages preview to successfully run for a brand new Next.js application created with npm create cloudflare@latest my-next-app -- --framework=next. After the changes I didn't even need WSL to get the Next.js app to finish building.

So at this time to do we not have out of the box support for Windows and Next.js development?

I'm planning to build a full-stack Next.js app that uses multiple Bindings so that will likely be a better test of building and preview environments on Windows.

@Puliczek
Copy link

Puliczek commented Sep 3, 2024

Same problem on my Windows:

image

@gandli
Copy link

gandli commented Oct 3, 2024

Similarly, I'm having this problem

@EdamAme-x
Copy link

EdamAme-x commented Oct 20, 2024

same issue on WSL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants