-
-
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
Deployed application fails with "500 internal error" on both netlify and vercel #8039
Comments
If you're seeing a Have you tried creating a minimal project that demonstrates the problem? |
On Netlify, "Deploy logs" are all green, "Function logs" only show "waiting for logs..." forever and nothing happens. The root page shows the error, same for
|
Okay, I was able to quickly throw together a minimal reproduction case: Clone https://github.com/mcmxcdev/sveltekit-issue-8039 locally, run it and navigate to blog and then to the single blog post entry. It should work as expected. The same project is deployed to https://main--stalwart-pika-07042f.netlify.app/, it will run into http 500 when preloading |
Haven't had a chance to run the repo yet, but the problem is almost certainly that you're trying to read content from the filesystem that doesn't exist in the serverless functions. We might add a way to include files in Lambda-based adapters in future, but until then if you want to access the filesystem (outside a non-Lambda Node.js deployment) then it has to be done during prerendering. Acknowledge that this could use a more helpful error. |
I've been using helper scripts in package.json to test locally what adapter-vercel and adapter-netlify builds do: {
scripts: {
"build:netlify": "cross-env NETLIFY=true pnpm build",
"build:vercel": "cross-env VERCEL=true pnpm build",
...
}
} Inspecting their outputs in ./build (for adapter-netlify) and ./.vercel/output (for adapter-vercel) and comparing to normal builds may shed some light. It may be even possible to serve them out (without svelte-kit built backend functions). I got my template created from SvelteKit demo app to deploy cleanly on both, and the above was instrumental to figure out what wrong info I picked from outdated Internet pages, which has plenty. Another thing I do regularly is make a clean SvelteKit demo app, and diff it to my code base. SvelteKit dev velocity is insanely high, and things change daily. |
That's a good hint and most likely the issue! So how can I now have blog posts loaded? No
I just tried to switch back to |
But if you enable You can add //+page.ts/js, and reset the offending flag for that page. I did so in my template project, and I have it build adapter-static/vercel/netlify without complaining. When dynamic page throws an error in the adapter, make |
No, it isn't. 'Dynamic' routes in the sense of dynamic parameters — |
They do support loading from the file system. The problem is that the file isn't there for them to load; it doesn't get moved into the relevant place for the functions, because there's no obvious need to do so. If your posts really are JSON, is it possible for you to import them, rather than using |
adapter-static provides a server, at least for |
Generally speaking, the adapters need more documentation on what they can and can't do. I really don't care which one to use but just want it to work.
That was a good suggestion and I tried to import This is what my posts file looks like: import fs from 'fs';
import frontMatter from 'front-matter';
import { marked } from 'marked';
import Prism from 'prismjs';
import 'prism-svelte';
import loadLanguages from 'prismjs/components/index.js';
import readingTime from 'reading-time';
loadLanguages(['shell', 'markdown', 'json']);
const posts = fs
.readdirSync('./src/posts')
.filter((elem) => elem.endsWith('.svx'))
.map((postFilename) => {
const postContent = fs.readFileSync(`./src/posts/${postFilename}`, {
encoding: 'utf8',
});
const postFrontMatter = frontMatter(postContent);
const renderer = new marked.Renderer();
renderer.code = (source, lang: string) => {
const html = Prism.highlight(source, Prism.languages[lang], lang);
return `<pre class='language-${lang}'><code class='language-${lang}'>${html}</code></pre>`;
};
const html = marked.parse(postFrontMatter.body, { renderer });
const readingTimeDuration = readingTime(postFrontMatter.body).text;
return {
// @ts-expect-error Spread types may only be created from object types.
...postFrontMatter.attributes,
html: marked.parse(html),
readingTime: readingTimeDuration,
};
});
const modifiedPosts = posts
.filter((post) => !post.hidden)
.sort((a, b) =>
new Date(a.creationDate).getTime() > new Date(b.creationDate).getTime()
? -1
: new Date(a.creationDate).getTime() < new Date(b.creationDate).getTime()
? 1
: 0,
);
export default modifiedPosts; |
Alas, I meant really a JSON file. Your example is an endpoint on your server, returning JSON, so you won't be able to load it from import - which only works for files directly available.oj disk. I have anecdotal success of doing what you're doing - anecdotal in that I no longer remember it all, but in a nutshell:
This means it would get imported at build time, and then get deployed - but you'd still develop against the local endpoint. |
The issue here is that the |
Describe the bug
I have been trying for a good 2 months now to get my Sveltekit website deployed and up-to-date again, but can't seem to figure out what's wrong.
The application is working just fine in dev and build + preview. Netlify and Vercel deployments are succeeding as well. As soon as I launch the page though, I am running into a completely useless "500 internal error" without any further logs or information about what the problem is.
I encounter these errors on all pages which load blog posts with code like
const allPosts = await fetch('/blog.json')
.Reproduction
I can offer to set my project temporarily to be public so that the code can be inspected.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: