-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
File cannot be read in prod #5163
Comments
Reading from the filesystem is not encouraged as the build output won't match the desired path as you do in dev. It works in dev because files are left as-is (unbundled) through the dev server. Ideally you should import them, or save it in a database, etc. Marking as duplicate of #3535 |
Thanks! This clarifies the issue a bit. One question: what do you mean exactly by importing the files? Also, why does the A big workaround is using mdsvex to preprocess the markdown files. This is explained in great detail here. But there must be a way to read markdown (or just plain text) files directly in SvelteKit, right? |
I think I have found a solution which works at least for Netlify and my toy example. It's similar to the solution at this stackoverflow question.
It works :) |
I am running into this same issue trying to call @ScriptRaccoon do you know if there is a similar mechanism to include additional files/directories for Vercel deployments? When I log the directory contents on the Vercel deployment (i.e.
Right now, I'm having to resort to force-enabling SSG on my entire site (with @sveltejs/adapter-static), but it would be nice to leverage server-side capabilities. |
Sorry, I have no experience with Vercel. |
@ScriptRaccoon No worries! I ended up discovering that leverage VIte's Granted, using Maybe in the future, SvelteKit will be able to expose the filesystem path to the compiled static assets directory. Because that would allow the file-reading to be real-time, rather than performed as a build step. |
Describe the bug
In the
get
function of a SvelteKit page endpoint I would like to read a file (withfs.readFileSync
) which is inside thesrc
folder and send the result to the client. This works fine in my local dev environment. But when I deploy the app to Netlify (for example) the following error shows up:I have tried to
NODE_VERSION
var)Maybe this is easy to solve by changing the path of the file (how?), but I really wonder why this works in dev, but not in prod.
Reproduction
npm init svelte
. No typescript, no prettier, no ESLint, no playwright.src/files/test.txt
with some sample text.index.svelte
:index.js
:npm run dev
and open the app, it shows the sample text from the file.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: