localhost:4321 (Astro, SharePoint SPFx): not working and fixes
Port 4321 is the default for the Astro dev server and for SharePoint Framework (SPFx) debugging. How to open it and fix refused to connect.
Open this address: http://localhost:4321This opens on your own computer. It only works if the program is running.
localhost:4321 is the default address of the Astro development server, shown in the terminal as Local http://localhost:4321/. SharePoint Framework (SPFx) projects also serve their debug files at https://localhost:4321. It only works while that dev server is running on your own computer.
What runs on localhost:4321
- Astro with
npm run devorastro dev, on http://localhost:4321 - SharePoint Framework (SPFx) with
heft start(newer projects) orgulp serve(older ones), on https://localhost:4321
Commands to start and test port 4321
npm run devnpx astro dev --port 4322npx astro dev --hostFind what is using port 4321
Run these in a terminal on your computer. Nothing is sent to this site.
If localhost:4321 will not open
- Port 4321 is already in use
- Another program is on port 4321. Find it with the tool below and stop it, or start yours on another port.
- Port 4321 is in use, trying another
- Astro usually picks the next free port and prints the new address. Open the one in the terminal.
- This site can’t be reached (ERR_CONNECTION_REFUSED)
- The server is not running. Start it and keep that terminal open. See the full checklist.
- Works on your computer, not on your phone
- Start the server on all network addresses and use your computer’s IP address. See how to open localhost from your phone.
- Astro will not start: Node version error
- Astro needs a recent Node.js version. The error message names the minimum. Run
node -v, update Node if it is older, then runnpm installagain. - 404 for a page that exists
- Astro makes routes from files in
src/pages. A file calledabout.astrothere becomes/about. Files outside that folder do not become pages. - Choose the port or the network address in the config
- In astro.config.mjs add
server: { port: 4322, host: true }.host: truelistens on your network so a phone or container can reach it. - Docker or WSL cannot reach it
- Run
astro dev --host. Inside a container, publish the port with-p 4321:4321. - Changes do not refresh on WSL or a network drive
- File watching can miss changes on drives that Linux mounts from Windows. Keep the project inside the WSL file system, or enable polling in the Vite settings.
- The page is blank and the terminal shows an error
- Read the first red error in the terminal, not the browser. A missing import or a bad front matter block stops the whole page.
- SPFx: the browser shows a certificate warning on https://localhost:4321
- SPFx serves over HTTPS with a developer certificate. Microsoft says you must trust it once per computer. Older gulp projects do this with
gulp trust-dev-cert. See Microsoft’s setup page for your SPFx version. - SPFx: SharePoint does not load my web part
- The page loads your code from
https://localhost:4321/temp/build/manifests.js. Add?debugManifestsFile=https%3A%2F%2Flocalhost%3A4321%2Ftemp%2Fbuild%2Fmanifests.js&debug=true&noredir=trueto the SharePoint page address, and keep the dev server running. - SPFx: ERR_CONNECTION_REFUSED with the server running
- In one Microsoft Q&A thread the cause was antivirus port monitoring (Kaspersky) blocking the local connection. Another answer there fixed it by moving the workbench port off 5432 in
config/serve.json. - SPFx: the online workbench is going away
- Microsoft says the SharePoint Framework online workbench is deprecated from 13 May 2026 and retires on 1 December 2026. Its replacement is the SPFx Debug Toolbar.
Other ports like 4321
| Port | Usually used by |
|---|---|
| localhost:3000 | React, Next.js, Express |
| localhost:5173 | Vite dev server |
| localhost:4200 | Angular dev server |
| localhost:5000 | Flask |
| localhost:8000 | Django, PHP, Python |
| localhost:8080 | Tomcat, Spring Boot, Docker |
| localhost:8888 | Jupyter Notebook |
Questions about localhost:4321
- What runs on localhost:4321?
- Most often the Astro development server. SharePoint Framework projects also use it for debug files, over https.
- How do I open it from my phone?
- Start it with --host so it listens on your network, then open your computer's IP address with :4321.
- How do I stop Astro on port 4321?
- Press Ctrl+C in the terminal that is running it. If the terminal is gone, find the process with the port checker below.
- How do I build for production instead?
- Run
npm run build. The static site is written to the dist folder. The dev server is not for production. - Is it http or https on port 4321?
- Astro uses http. SharePoint Framework uses https with a developer certificate.