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
What version of wrangler? I just checked with 3.83.0 and it worked as expected for me. Can you paste your toml?
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
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
Yeah, I tried that also. But it keeps ignoring nested directories.
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)
This is as same as my setup.
But t1 directory is not uploaded.
➜ 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
⛅️ 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)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.
(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?
Okay sure. I will create a repository. Thank you.
Yeah absolutely, thank YOU for troubleshooting this with me!
Here is a repository with the files.
https://github.com/ThevinSenath/worker-test.git
🌀 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
I also think so.
What's the output from your wrangler deploy btw? Is it only uploading 1 file?
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
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 worldYeah but it gives 404 error.
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
?I made a change index.html file inside the t1 directory. But it keeps saying no assets to upload.
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)
Yes I created a new text file as you suggested. But it keeps ignoring when deploying.
I had a couple folks on win10 and win11 try your repo, and they're all seeing 3 files uploaded. What's your OS?
It's windows 11.
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!
Can anything happen because of the cloudflare account?
Thank you for your help.
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
Hmm it is so much confusing for me why it is not working.
Okay thank you.
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)
Hi, maybe there is a mistake from my end. Anyway thank you for the help.
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
Hi, did you guys create the worker using this command?
npm create cloudflare@latest -- my-static-site --experimental
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
What did you mean by verifying using c3?
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 wranglerCloudflare 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.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?
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
Hmm when I do the same it is not working. Anyway thank you again mate. 💕
@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 solutionHi @pas94 unfortunately I couldn’t find any solution yet.
@texan any updates on this
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.
Hi, anyone found a solution? 🥲
@texan anyone from the cloudflare team that can address this?
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.