You can use Astro with Deno by creating the project with deno run -A npm:create-astro@latest, then running deno task dev and deno task build instead of the npm scripts. Deno 2 reads package.json and installs npm packages, so a standard Astro project works without changes. Static builds deploy anywhere, including Deno Deploy; server-rendered routes need the community Deno adapter.
Astro is developed and tested primarily against Node.js, so Deno is a supported path rather than the default one. For most content sites, that makes little difference: Deno runs the build, and the output is plain HTML, CSS and JavaScript.
Key Takeaways
- Deno 2 runs Astro projects through its npm compatibility layer, using your existing
package.json.- Use
deno task <script>to run thedev,buildandpreviewscripts.- Static output from
astro buildneeds no runtime at all and deploys to Deno Deploy or any static host.- For on-demand rendering on Deno, use the Deno team’s
@deno/astro-adapterand check its supported Astro versions first.- If a dependency misbehaves under Deno, the Node.js toolchain remains the reference environment for Astro.
Why run Astro with Deno
Teams choose Deno for a few practical reasons:
- One binary. Deno includes a runtime, package manager, formatter, linter and test runner.
- Permissions. Scripts run with explicit permissions, which limits what a compromised dependency can do.
- TypeScript without setup for scripts outside Astro, such as content import tools.
- Deno Deploy. If your team already hosts services there, it is convenient to keep the site on the same platform.
None of these change how Astro itself works. Components, content collections, images and integrations behave the same, because Deno executes the same JavaScript Astro ships for Node.js.
Create an Astro project with Deno
Run the official create command through Deno’s npm specifier:
deno run -A npm:create-astro@latest my-site
cd my-site
deno install
deno install reads package.json and installs dependencies into node_modules/, which Astro and Vite expect. The -A flag grants all permissions to the installer, because it writes files and runs package scripts. In CI, you can narrow permissions once you know what the project needs.
To start from a theme instead of a starter, clone its repository and run deno install in it. The getting started docs cover cloning and running a theme locally; replace npm commands with their Deno equivalents.
Run the dev server and build
Deno runs scripts from package.json with deno task:
deno task dev # astro dev on http://localhost:4321
deno task build # astro build to dist/
deno task preview # serve the production build locally
You can also call the Astro CLI directly, which is handy for commands like astro add or astro check:
deno run -A npm:astro add mdx sitemap
deno run -A npm:astro check
If you prefer, add a deno.json with tasks that mirror your npm scripts, so contributors who never touch npm have obvious commands:
{
"tasks": {
"dev": "deno run -A npm:astro dev",
"build": "deno run -A npm:astro build",
"preview": "deno run -A npm:astro preview"
},
"nodeModulesDir": "auto"
}
nodeModulesDir: "auto" tells Deno to keep a node_modules/ folder, which Vite and many Astro integrations rely on to resolve packages. The CLI commands cheatsheet lists the Astro commands you will run this way.
Static sites: no adapter needed
By default, astro build writes static files to dist/. Deno only runs the build; the output does not depend on Deno. You can host it on:
- Deno Deploy, by deploying the
dist/folder as static assets. - Cloudflare Pages, Netlify, Vercel or GitHub Pages, exactly as you would with a Node.js build.
For static hosts that build from your repository, set the build command to deno task build if the host supports Deno, or keep a Node.js build there. Both produce the same files. The static deployment docs cover each host, and the deployment guide compares them.
Server rendering on Deno
To render pages on request, Astro needs an adapter for the runtime. Astro’s official adapters target Node.js, Netlify, Vercel and Cloudflare. For Deno, the Deno team maintains @deno/astro-adapter:
deno add npm:@deno/astro-adapter
// astro.config.mjs
import { defineConfig } from 'astro/config';
import deno from '@deno/astro-adapter';
export default defineConfig({
output: 'server',
adapter: deno(),
});
After deno task build, the server entry is in dist/server/, and you run it with Deno:
deno run --allow-net --allow-read --allow-env ./dist/server/entry.mjs
Community adapters can lag behind major Astro releases. Before you rely on it, check the adapter’s README and release notes for the Astro versions it supports. If it does not yet support your Astro version, two fallbacks work:
- Use
@astrojs/nodein standalone mode and run the output with Deno’s Node.js compatibility. - Keep pages static and move dynamic parts into server islands or a separate API.
The Astro SSR guide explains when you need a server at all.
Environment variables
Astro reads .env files through Vite, and astro:env validates variables against a schema. That works the same under Deno:
// astro.config.mjs
import { defineConfig, envField } from 'astro/config';
export default defineConfig({
env: {
schema: {
API_URL: envField.string({ context: 'server', access: 'public' }),
API_TOKEN: envField.string({ context: 'server', access: 'secret' }),
},
},
});
// src/pages/api/status.ts
import type { APIRoute } from 'astro';
import { API_URL, API_TOKEN } from 'astro:env/server';
export const prerender = false;
export const GET: APIRoute = async () => {
const res = await fetch(`${API_URL}/status`, { headers: { Authorization: `Bearer ${API_TOKEN}` } });
return new Response(await res.text(), { headers: { 'Content-Type': 'application/json' } });
};
At runtime, Deno needs --allow-env to read environment variables. Prefer astro:env over Deno.env.get() in Astro code, so the same project still runs on Node.js. The Astro environment variables docs cover the full API.
Deploying to Deno Deploy
Deno Deploy can build from a GitHub repository. A typical setup:
- Connect the repository in the Deno Deploy dashboard.
- Set the install command to
deno installand the build command todeno task build. - For a static site, serve the
dist/directory as static files. - For a server build with the Deno adapter, set the entrypoint to
dist/server/entry.mjs. - Add environment variables in the project settings.
Deno Deploy’s build and configuration screens change over time, so follow Deno’s Astro guide for current settings.
Common issues
| Symptom | Likely cause | Fix |
|---|---|---|
Cannot find module during build |
No node_modules/ folder |
Set "nodeModulesDir": "auto" and run deno install |
| Integration fails with native code errors | Package uses Node-API binaries | Check Deno compatibility, or build on Node.js |
PermissionDenied at runtime |
Missing permission flag | Add --allow-net, --allow-read or --allow-env |
| Sharp image errors | Native image library not resolved | Reinstall with deno install --allow-scripts, or use a passthrough image service |
| Adapter type errors after upgrading Astro | Adapter behind Astro release | Pin Astro to a supported version or use @astrojs/node |
Sharp, which Astro uses for image optimisation, installs a native binary through a postinstall script. Deno does not run lifecycle scripts by default, so allow them for Sharp, for example with deno install --allow-scripts=npm:sharp. The missing Sharp fix covers the error message you will see otherwise.
Should you use Deno or Node.js for Astro?
Use Node.js if you want the path Astro’s team tests most, the widest compatibility with integrations, and the simplest CI on every host.
Use Deno if your team already standardises on it, you value its permission model and built-in tooling, or you deploy to Deno Deploy. For static sites, the risk is low, because the output does not depend on the runtime.
Every Komal Astro theme builds to static output, so it can be built with either runtime and deployed to any static host.
FAQ
Does Astro work with Deno?
Yes. Deno 2 supports npm packages and package.json, so standard Astro projects run with deno task dev and deno task build. Astro’s primary target is Node.js, so check unusual integrations under Deno before relying on them.
How do I create an Astro project with Deno?
Run deno run -A npm:create-astro@latest, then deno install in the new folder. Use deno task dev to start the dev server.
Is there an official Astro adapter for Deno?
The Deno adapter, @deno/astro-adapter, is maintained by the Deno team rather than the Astro core team. It enables on-demand rendering on Deno and Deno Deploy. Check its README for the Astro versions it supports.
Can I deploy a static Astro site to Deno Deploy?
Yes. Build with deno task build and serve the dist/ folder as static files. No adapter is required for static output.
Is Astro faster on Deno than on Node.js?
For static sites, visitors get the same files either way, so page speed is identical. Build times are usually similar. Measure your own project if build speed matters.