🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Fundamentals••By Komal Nakrani

Fix: Astro Configuration File Not Found

Fix the Astro configuration file not found error: correct the --config path, remember it resolves from the project root, and use a file name Astro accepts.

#Astro#Errors#CLI#Configuration

“Specified configuration file not found.” appears when you pass --config to an Astro command and the file doesn’t exist at that path. The message shows what Astro tried: “Unable to resolve --config "astro.staging.mjs". Does the file exist?” Astro joins the --config value to the project root, so check the path from the root (or from --root if you set it), fix typos and the extension, and run the command again.

Key Takeaways

  • This error only happens with an explicit --config flag. Without it, Astro searches for a config file itself.
  • The --config path is resolved from the project root, not from wherever a script happens to run.
  • Without --config, Astro looks for astro.config.mjs, .js, .ts or .mts in the root, in that order.
  • In monorepos, set --root to the app folder or run the command from inside it.

How Astro finds the config

Without a flag, Astro checks the project root for these files, in order:

astro.config.mjs
astro.config.js
astro.config.ts
astro.config.mts

If none exists, Astro runs with defaults rather than failing. With --config, Astro skips the search and requires that exact file:

# Terminal
npx astro build --config astro.staging.mjs

If astro.staging.mjs isn’t in the root, you get “Specified configuration file not found.”

Fix 1: check the path from the root

Astro resolves the value relative to the project root. These two commands point at the same file:

# Terminal: run from the project root
npx astro build --config config/astro.staging.mjs
npx astro build --root . --config config/astro.staging.mjs

Pass a relative path. Astro joins the value onto the root, so an absolute path like /Users/me/site/astro.config.mjs becomes the root plus that whole path and won’t resolve. If you pass --root ./apps/site, the config path is resolved from apps/site/, not from where you typed the command. A common mistake is repeating the folder:

# Looks for apps/site/apps/site/astro.config.mjs
npx astro build --root apps/site --config apps/site/astro.config.mjs

# Correct
npx astro build --root apps/site --config astro.config.mjs

Fix 2: check the name and extension

List what’s actually there:

# Terminal
ls astro.config.* config/ 2>/dev/null

Look for astro.config.mjs versus astro.config.mts, a .ts file referenced as .js, or a file that exists locally but isn’t committed, so CI can’t find it.

Fix 3: check npm scripts

Scripts in package.json run from the folder containing that package.json. In a monorepo, a root script calling the app’s Astro binary needs --root:

{
  "scripts": {
    "build:site": "astro build --root apps/site",
    "build:staging": "astro build --root apps/site --config astro.staging.mjs"
  }
}

Alternatively, run the script inside the app with your package manager’s workspace flag, such as npm run build --workspace apps/site.

Do you need a second config?

Multiple config files are useful for staging builds with a different site URL, but environment variables are often simpler:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: process.env.SITE_URL ?? 'https://www.example.com',
});

Then SITE_URL=https://staging.example.com npm run build gives you a staging build from one file. The environment variables guide covers astro:env for typed variables, and the config cheatsheet lists the common options. Our Astro config docs show the config file shipped with Komal Astro themes, and the official CLI reference documents --config and --root.

FAQ

Where should astro.config.mjs be?

In the project root, next to package.json. Astro finds it there automatically, so most projects never need --config.

Can I use astro.config.ts?

Yes. Astro looks for astro.config.ts and astro.config.mts as well as .mjs and .js. TypeScript configs get type checking without extra setup.

Is the –config path relative to the current folder?

It’s resolved from the project root, which is the current folder unless you pass --root. With --root, give the config path relative to that root.