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: Cannot wrangler pages deploy with pnpm from subdirectory #6224

Open
IanVS opened this issue Jul 8, 2024 · 7 comments
Open

🐛 BUG: Cannot wrangler pages deploy with pnpm from subdirectory #6224

IanVS opened this issue Jul 8, 2024 · 7 comments
Labels
bug Something that isn't working pages Relating to Pages

Comments

@IanVS
Copy link

IanVS commented Jul 8, 2024

Which Cloudflare product(s) does this pertain to?

Pages, Wrangler core

What version(s) of the tool(s) are you using?

3.63.1 [wrangler]

What version of Node are you using?

20.11.1

What operating system and version are you using?

macos sonoma 14.5

Describe the Bug

Observed behavior

I build my pages project into a subdirectory which includes my functions, so I need to run pnpm wrangler pages deploy from that directory. But when I do, wrangler seems to look in the wrong spot for the wrangler tmp.

My project root is /Users/ianvs/code/defined/webclient, and i run the following command from /Users/ianvs/code/defined/webclient/.definednet:

> pnpm wrangler pages deploy build/
✨ Compiled Worker successfully

✘ [ERROR] ENOENT: no such file or directory, open '/Users/ianvs/code/defined/.wrangler/tmp/pages-F5FXhL/functionsWorker-0.20030179475032694.js'

Note that it is not looking in code/defined/webclient, but rather code/defined, one directory too high. The listed file does exist in the correct code/defined/webclient/.wrangler/tmp directory.

Expected behavior

Should execute successfully

Steps to reproduce

  1. in a cloudflare pages project containing worker functions, move those functions into a subdirectory, and build your project into that directory as well.
  2. from that directory, using pnpm, run pnpm wrangler pages deploy against your built project.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@IanVS IanVS added the bug Something that isn't working label Jul 8, 2024
@CarmenPopoviciu CarmenPopoviciu added the pages Relating to Pages label Jul 22, 2024
@CarmenPopoviciu
Copy link
Contributor

hi @IanVS

thank you for reporting this issue with us.

I am not able to reproduce this behaviour. I used https://github.com/cloudflare/workers-sdk/tree/main/fixtures/pages-functions-with-routes-app as my test Pages app. In this project, I:

  • created a new folder called ./test-app
  • moved public and functions inside of that new folder
  • ran npx wrangler pages deploy public from test-app

The .wrangler/tmp folder is correctly created under pages-functions-with-routes, and the app works correctly too.

I noticed you are running the dev command with pnpm and was wondering if you're not in fact meaning to run npx instead?

@CarmenPopoviciu CarmenPopoviciu added the awaiting reporter response Needs clarification or followup from OP label Jul 22, 2024
@IanVS
Copy link
Author

IanVS commented Jul 22, 2024

Hi @CarmenPopoviciu thanks for taking a look.

I use pnpm in my project, so I did intend to use that, rather than npx. Note that it's in the issue description as well. I hit this error when using wrangler-action, with the packageManager: pnpm flag.

@petebacondarwin petebacondarwin added awaiting Cloudflare response Awaiting response from workers-sdk maintainer team and removed awaiting reporter response Needs clarification or followup from OP labels Jul 30, 2024
@edmundhung
Copy link
Member

edmundhung commented Sep 9, 2024

Hi @IanVS,

I tried running pnpm wrangler pages deploy but couldn't reproduce the issue. Could you share more details or steps to help us replicate it on our end? A minimal reproduction would be really helpful. Thank you!

@edmundhung edmundhung added awaiting reporter response Needs clarification or followup from OP and removed awaiting Cloudflare response Awaiting response from workers-sdk maintainer team labels Sep 9, 2024
@IanVS
Copy link
Author

IanVS commented Sep 9, 2024

Thanks for taking a look @edmundhung. Here's a minimal reproduction: https://github.com/IanVS/cloudflare-workers-issue-6224. Steps are in the README.

@lrapoport-cf lrapoport-cf added awaiting Cloudflare response Awaiting response from workers-sdk maintainer team and removed awaiting reporter response Needs clarification or followup from OP labels Sep 16, 2024
@CarmenPopoviciu
Copy link
Contributor

CarmenPopoviciu commented Sep 16, 2024

hi @IanVS,

thank you so much for the reproduction repository ❤️. It was extremely helpful in understanding what the issue at hand is. I can indeed confirm that if I run pnpm reproduce in that repro project results in [ERROR] ENOENT: no such file or directory, scandir '/Users/ianvs/code/experiments/cloudflare-pnpm-repro/build', however it appears the main issue here is not an issue with Pages itself, but is rather related to how your build/deploy scripts are set up.

The reason you're seeing that error is because Pages attempts to resolve the directory of static assets, in this case build, relative to the current working directory (which is the directory that was current when you started the reproduce command), in this case cloudflare-workers-issue-6224. The fact that your script cds into the .dist folder has no effect on how the cwd is evaluated, and therefore, Pages will attempt to find /cloudflare-pnpm-repro/build and error, since that directory does not exist.

The fix here would be pretty straightforward, in that you could have the deploy script run pnpm wrangler pages deploy ./.dist/build/, instead, which would work as expected. There's a caveat to that though.

Pages expects the dev/deploy commands to be run from what we call the "root" of the Pages project. This is where your functions should live, if any exist, and where Pages will look for Functions by default. In most of the cases, this will also be the root of your project.

In your example, the functions directory lives in cloudflare-workers-issue-6224/.dist, however, the reproduce command is run from its parent folder, cloudflare-workers-issue-6224. When Pages attempts to resolve the functions directory, it will again try to resolve it relative to the current working directory, and again fail. So my proposed fix would get the project deployed, but without your Functions.

Currently we do not support customising the path of the functions directory, and there are no current plans to do so. The simplest fix here would be to have your Functions live in the root of your project if possible. Otherwise you could:

  • adapt your scripts to factor in how the cwd is resolved
  • or run the build and deploy scripts separately

I hope this helps, but let me know if you have any more questions <3

@IanVS
Copy link
Author

IanVS commented Sep 16, 2024

Thanks for taking a look, @CarmenPopoviciu, but I have to question one thing. You said that wrangler uses cwd to determine where to look for static assets. But if that's the case, why does it still break when I manually cd .dist and then run pnpm wrangler pages deploy build/ directly from there? In that case cwd should for sure be cloudflare-workers-issue-6224/.dist, but it still tries to look in the project root instead. Furthermore, using npx wrangler pages deploy build/ from that subdirectory succeeds without any issue.

Considering this is supported in npx and not pnpm, and seems unrelated to cwd, would you consider reopening this issue?

@CarmenPopoviciu
Copy link
Contributor

oh! you are right indeed. I was very convinced I tried running that manually and had it working, but it's very possible I was running npx instead of pnpm. The cwd seems to have been a red herring in this case. Reopening. Thx for catching that!

@CarmenPopoviciu CarmenPopoviciu removed the awaiting Cloudflare response Awaiting response from workers-sdk maintainer team label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working pages Relating to Pages
Projects
Status: Backlog
Development

No branches or pull requests

5 participants