From 1818dfd452c2fc83d9d2a5791f380f50e84ccbd7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 19 Jan 2024 10:20:18 -0500 Subject: [PATCH 1/2] chore: update troubleshooting docs --- .../docs/25-build-and-deploy/60-adapter-cloudflare.md | 2 +- .../25-build-and-deploy/70-adapter-cloudflare-workers.md | 2 +- .../docs/25-build-and-deploy/80-adapter-netlify.md | 6 +++++- documentation/docs/25-build-and-deploy/90-adapter-vercel.md | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md index 033a01c8247d..ab59adbe1a25 100644 --- a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md +++ b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md @@ -108,4 +108,4 @@ You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit s ### Accessing the file system -You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content. +You can't use `fs` in workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. diff --git a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md index f0f11e7c682e..667527c8bf0f 100644 --- a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md +++ b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md @@ -127,4 +127,4 @@ When deploying to workers, the server generated by SvelteKit is bundled into a s ### Accessing the file system -You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content. +You can't use `fs` in workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. diff --git a/documentation/docs/25-build-and-deploy/80-adapter-netlify.md b/documentation/docs/25-build-and-deploy/80-adapter-netlify.md index 9daffeccdf7c..a9d5702b3b14 100644 --- a/documentation/docs/25-build-and-deploy/80-adapter-netlify.md +++ b/documentation/docs/25-build-and-deploy/80-adapter-netlify.md @@ -111,4 +111,8 @@ Additionally, you can add your own Netlify functions by creating a directory for ### Accessing the file system -You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content. +You can't use `fs` in edge deployments. + +You _can_ use it in serverless deployments, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the `read` function from `$app/server` to access your files. `read` does not work inside edge deployments (this may change in future). + +Alternatively, you can [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. diff --git a/documentation/docs/25-build-and-deploy/90-adapter-vercel.md b/documentation/docs/25-build-and-deploy/90-adapter-vercel.md index 31ec3d20092b..ae9b91444c6f 100644 --- a/documentation/docs/25-build-and-deploy/90-adapter-vercel.md +++ b/documentation/docs/25-build-and-deploy/90-adapter-vercel.md @@ -157,4 +157,8 @@ Projects created before a certain date may default to using an older Node versio ### Accessing the file system -You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content. +You can't use `fs` in edge functions. + +You _can_ use it in serverless functions, but it won't work as expected, since files are not copied from your project into your deployment. Instead, use the `read` function from `$app/server` to access your files. `read` does not work inside routes deployed as edge functions (this may change in future). + +Alternatively, you can [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. From 35c6c1c01a41f5fbf57f746d9c726615c9d3fc57 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 19 Jan 2024 16:28:06 -0500 Subject: [PATCH 2/2] Apply suggestions from code review --- documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md | 2 +- .../docs/25-build-and-deploy/70-adapter-cloudflare-workers.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md index ab59adbe1a25..5859d1326fbc 100644 --- a/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md +++ b/documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md @@ -108,4 +108,4 @@ You may wish to refer to [Cloudflare's documentation for deploying a SvelteKit s ### Accessing the file system -You can't use `fs` in workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. +You can't use `fs` in Cloudflare Workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. diff --git a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md index 667527c8bf0f..68e54b320a7b 100644 --- a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md +++ b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md @@ -127,4 +127,4 @@ When deploying to workers, the server generated by SvelteKit is bundled into a s ### Accessing the file system -You can't use `fs` in workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question. +You can't use `fs` in Cloudflare Workers — you must [prerender](https://kit.svelte.dev/docs/page-options#prerender) the routes in question.