Nested directories are not working in Static Assets

Hi, I am creating a Hello World Static Assets worker. I want to have nested folders inside the public directory, so that my URLs will look like below t1/hello.html , t2/en.json etc. But when I tried it, wrangler deploy keeps ignoring nested directories and only uploading the files inside the public directory.
47 Replies
texan
texan2mo ago
What version of wrangler? I just checked with 3.83.0 and it worked as expected for me. Can you paste your toml?
KingsLayer
KingsLayer2mo ago
Hi @texan, I also have the same issue with wrangler 3.83.0. Here is my toml file. #:schema node_modules/wrangler/config-schema.json name = "rubix-test" compatibility_date = "2024-10-22" assets = { directory = "./public/" } [observability] enabled = true
texan
texan2mo ago
Out of curiosity, can you drop the trailing slash on your directory? I’m not at my laptop at the moment but that sticks out to me as different than I’ve been using
KingsLayer
KingsLayer2mo ago
Yeah, I tried that also. But it keeps ignoring nested directories.
texan
texan2mo ago
Hmmm, I would definitely be interested in getting a repo from you. This is what my setup looks like: ➜ assets-upload-nested-repro find public public public/index.html public/world public/world/world.txt public/hello public/hello/hello.txt ➜ assets-upload-nested-repro cat wrangler.toml #:schema node_modules/wrangler/config-schema.json name = "nested-dir-repro" compatibility_date = "2024-10-22" assets = { directory = "./public/" } [observability] enabled = true ➜ assets-upload-nested-repro npx wrangler deploy ⛅️ wrangler 3.83.0 ------------------- 🌀 Building list of assets... 🌀 Starting asset upload... 🌀 Found 3 new or modified static assets to upload. Proceeding with upload... + /hello/hello.txt + /world/world.txt + /index.html Uploaded 1 of 3 assets Uploaded 2 of 3 assets Uploaded 3 of 3 assets ✨ Success! Uploaded 3 files (1.26 sec)
KingsLayer
KingsLayer2mo ago
This is as same as my setup.
No description
KingsLayer
KingsLayer2mo ago
But t1 directory is not uploaded.
texan
texan2mo ago
➜ assets-upload-nested-repro find public -type f public/index.html public/hi.html public/t1/index.html ➜ assets-upload-nested-repro npx wrangler deploy
⛅️ wrangler 3.83.0 ------------------- 🌀 Building list of assets... 🌀 Starting asset upload... 🌀 Found 3 new or modified static assets to upload. Proceeding with upload... + /hi.html + /index.html + /index.html Uploaded 1 of 3 assets Uploaded 2 of 3 assets Uploaded 3 of 3 assets ✨ Success! Uploaded 3 files (1.26 sec) (Could use a little better output messaging on the files, but you can see it did both index files). Maybe permissions on the directories? Can we do a ls -la public and ls -la public/t1? Also, I see the "U" (unmodified?) in your screenshot for 2 of those files, are you sure those files have been written to disk? (The ls will confirm this as well)
KingsLayer
KingsLayer2mo ago
Volume in drive C has no label. Volume Serial Number is C8EB-899B Directory of \rubix-test File Not Found Directory of \rubix-test\public 10/29/2024 04:33 PM <DIR> . 10/29/2024 03:45 PM <DIR> .. 10/29/2024 04:33 PM 253 hi.html 10/28/2024 12:16 PM 246 index.html 10/29/2024 04:24 PM <DIR> t1 2 File(s) 499 bytes 3 Dir(s) 208,605,880,320 bytes free This is the output it gave.
texan
texan2mo ago
(Feel free to redact your paths btw 😅 ) So definitely looks like those files are written. hmm.. you're on windows (I'm using a mac). Any chance you can push up a public repository I can try to reproduce from?
KingsLayer
KingsLayer2mo ago
Okay sure. I will create a repository. Thank you.
texan
texan2mo ago
Yeah absolutely, thank YOU for troubleshooting this with me!
KingsLayer
KingsLayer2mo ago
Here is a repository with the files. https://github.com/ThevinSenath/worker-test.git
texan
texan2mo ago
🌀 Building list of assets... 🌀 Starting asset upload... 🌀 Found 3 new or modified static assets to upload. Proceeding with upload... + /hi.html + /index.html + /t1/index.html Uploaded 1 of 3 assets Uploaded 2 of 3 assets Uploaded 3 of 3 assets ✨ Success! Uploaded 3 files (1.06 sec) Yeah, looks like that's working on my mac: https://rubix-test.williamtaylor.workers.dev/t1/index.html I wonder if there's something about windows that isn't playing well. @DeltaOne would be interested to know your OS as well
KingsLayer
KingsLayer2mo ago
I also think so.
texan
texan2mo ago
What's the output from your wrangler deploy btw? Is it only uploading 1 file?
KingsLayer
KingsLayer2mo ago
It says no files to upload when I add a nested directory. 🌀 Building list of assets... 🌀 Starting asset upload... No files to upload. Proceeding with deployment... Total Upload: 0.31 KiB / gzip: 0.22 KiB Uploaded rubix-test (10.11 sec) Deployed rubix-test triggers (1.38 sec) https://rubix-test.rubix.workers.dev Current Version ID: 6776e0a3-d5e2-40ef-a009-f6c190adf5be
texan
texan2mo ago
OHH ok now we're getting somewhere. So that message just means all the assets are already known by workers. It didn't need to reupload them Though, https://rubix-test.rubix.workers.dev/t1/index.html should give you your t1 hello world
KingsLayer
KingsLayer2mo ago
Yeah but it gives 404 error.
texan
texan2mo ago
For kicks and giggles, can you use the command line to write a file to the public/t1 directory? Something like cd . > test.txt? Then go back up to your root and npx wrangler deploy?
KingsLayer
KingsLayer2mo ago
I made a change index.html file inside the t1 directory. But it keeps saying no assets to upload.
texan
texan2mo ago
If the hash is the same as a file you've previously uploaded for that worker, it won't re-upload. Try to make it's actually a change which hasn't been uploaded (eg. "hello world 11:13pm") Not sure how to make sure it's saved, but that's also got me suspicious (Which is why I recommended writing a new file via command line to rule that out)
KingsLayer
KingsLayer2mo ago
Yes I created a new text file as you suggested. But it keeps ignoring when deploying.
texan
texan2mo ago
I had a couple folks on win10 and win11 try your repo, and they're all seeing 3 files uploaded. What's your OS?
KingsLayer
KingsLayer2mo ago
It's windows 11.
texan
texan2mo ago
I'm a bit out of ideas here, but let me regroup in the morning and see if other folks on the team might have any ideas. Sorry you're running into this, I know it's a heck of a barrier to getting started!
KingsLayer
KingsLayer2mo ago
Can anything happen because of the cloudflare account? Thank you for your help.
texan
texan2mo ago
I don't think that's the case here. Wrangler is generating a list of files to upload based on what it's seeing in the public directory, and then reconciling files it needs to still upload with the server. If you've changed your t1/index.html file to be something you absolutely have not uploaded before (for this script), it should pick it up as needing to be uploaded. (and the output would indicate that it's uploading it) There might be some debug logs we can turn on to see what files it's scraping, but I'll have to ask another team for an assist
KingsLayer
KingsLayer2mo ago
Hmm it is so much confusing for me why it is not working. Okay thank you.
texan
texan2mo ago
Hey King, no update other than I've had a few more windows users try out your repo without any issues. I did track down the debug logs for wrangler but they don't output the file it's attempting to reconcile, so they aren't super helpful right now (I've filed a ticket to augment those logs in the future, but it's low priority)
KingsLayer
KingsLayer2mo ago
Hi, maybe there is a mistake from my end. Anyway thank you for the help.
texan
texan2mo ago
I know it's frustrating. Will continue to keep a look out in case it's more widespread. Thanks for going through the troubleshooting steps with me
KingsLayer
KingsLayer2mo ago
Hi, did you guys create the worker using this command? npm create cloudflare@latest -- my-static-site --experimental
texan
texan2mo ago
I did not-- I created it by cloning your repo and doing npx wrangler@latest deploy Also just verified using c3 that nested directories are working, which I would suspect. The c3 create is just for creating new projects from templates-- your wrangler deploy wouldnt (shouldnt?) be any different than creating the project by hand
KingsLayer
KingsLayer2mo ago
What did you mean by verifying using c3?
texan
texan2mo ago
c3 = create cloudflare cli. It's the npm create cloudflare command you're using. It just basically dumps a new project, but wouldnt have any impact on your file uploads. That's entirely wrangler
texan
texan2mo ago
Cloudflare Docs
CLI | Cloudflare Pages docs
Use C3 (create-cloudflare CLI) to set up and deploy new applications using framework-specific setup guides to ensure each new application follows Cloudflare and any third-party best practices for deployment.
KingsLayer
KingsLayer2mo ago
Thank you… That means you just clone my repo and then run npx wrangler@latest deploy. With that all the assests uploaded including t1 directory? Doesn’t it?
texan
texan2mo ago
Yup exactly. I also tried doing the c3 command you gave, and then created the t1 dir and t1/index.html, just like you had it, but no dice
KingsLayer
KingsLayer2mo ago
Hmm when I do the same it is not working. Anyway thank you again mate. 💕
pas94
pas942mo ago
@Will Taylor | Workers @KingsLayer I'm experiencing the same issue, if there is a nested folder for the static assets, it won't load the static files here is the structure I have === wrangler.toml === name = "test-app" main = "server/index.js" compatibility_date = "2024-10-11" compatibility_flags = ["nodejs_compat"] workers_dev = true account_id = "..." assets = { directory = "./server/public/", binding = "ASSETS", html_handling = "force-trailing-slash", not_found_handling = "single-page-application" } === folder structure === root-app-folder server/ public/ css/ styles.css scripts/ auth.js index.js index.html index.js package.json wrangler.toml === server/index.js === export default { async fetch(request, env) { const url = new URL(request.url); if (url.pathname.startsWith("/api/")) { // TODO: Add your custom /api/* logic here. return new Response("Ok"); } // Passes the incoming request through to the assets binding. // No asset matched this request, so this will evaluate not_found_handling behavior. console.log('request.url', request.url) return env.ASSETS.fetch(request); }, }; === server/public/index.html === <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Awesome Website Landing Page</title> <link rel="stylesheet" href="/css/styles.css"> </head> <body> ... <script type="module" src="/scripts/index.js"></script> </body> </html> @KingsLayer @Will Taylor | Workers wragnler dev doesn't work for the nested routes, (css/styles.css and scripts/index.js) if I take them out to the folder above them, which is "public" folder, it works, index.html gets fetched properly because its in the public folder, there must be something going on, @KingsLayer let me know if you found a solution
KingsLayer
KingsLayer2mo ago
Hi @pas94 unfortunately I couldn’t find any solution yet.
pas94
pas942mo ago
@texan any updates on this
muslax
muslax2mo ago
Hi, I'm experiencing the same issue... I'm using mac. It's weird... I tested with my second account on my macbook it's jusk ok. But back to my main account, the issue still exists.
KingsLayer
KingsLayer2mo ago
Hi, anyone found a solution? 🥲
pas94
pas942mo ago
@texan anyone from the cloudflare team that can address this?
texan
texan2mo ago
I think this has somewhat stalled because it's been difficult to get a repro. It seems like your issue might actually be different from KingsLayer (their issue was files not being uploaded during wrangler deploy). Would you be able to get a small github repo together and I can see if there's someone on the team who might be able to help? @pas94 would you be able to file a github issue against workers-sdk with some details and/or repro? That would help us get this prioritized and eyes on it.
Want results from more Discord servers?
Add your server