SvelteKit无法执行npm run start及生产Node服务器启动方式咨询
Hey there! Let's walk through how to get your production Node server up and running, and touch on your earlier note too.
First, kudos on fixing the config.kit.adapter issue by installing @sveltejs/adapter-node@next—it’s super frustrating when tooling updates outpace documentation, so I totally get your wish for more timely docs.
Now, onto your current problem with npm run start: The reason you’re seeing that preview message is that recent SvelteKit updates changed the default start script to point to svelte-kit preview, which is only meant for local checks of your production build, not actual production use. Here’s how to properly launch your production Node server:
Step 1: Build your production bundle
First, make sure you’ve compiled your project for production. Run this command:npm run buildThis uses the adapter-node you installed to generate a production-ready Node.js bundle, which will be saved in the
builddirectory by default.Step 2: Launch the production server
Instead of relying on the defaultstartscript, run the entry point of your built bundle directly:node build/index.jsStep 3: Update your
package.json(optional but recommended)
To getnpm run startworking like it did before, edit yourpackage.json’sscriptssection to point to the built Node file instead of the preview command. It should look something like this:"scripts": { "dev": "svelte-kit dev", "build": "svelte-kit build", "start": "node build/index.js", "preview": "svelte-kit preview" }Now, when you run
npm run start, it’ll launch your actual production Node server, not just a preview.
That should get you up and running properly in production.
内容的提问来源于stack exchange,提问作者Martin Weissenboeck

