sveltejs/kit · error · Error

Failed to parse netlify.toml: ${err.message}

Error message

Failed to parse netlify.toml: ${err.message}

What it means

adapter-netlify reads netlify.toml at build time to learn your build.publish and functions directories. If the TOML is syntactically invalid, the parser fails and the adapter rethrows with 'Failed to parse netlify.toml:' plus the underlying parser message (original error attached as cause).

Source

Thrown at packages/adapter-netlify/index.js:225

	// Copy user's custom _redirects file if it exists
	if (existsSync('_redirects')) {
		builder.log.minor('Copying user redirects...');
		const redirects_file = join(publish, '_redirects');
		builder.copy('_redirects', redirects_file);
	}
}

/**
 * @returns {NetlifyConfig | null}
 */
function get_netlify_config() {
	if (!existsSync('netlify.toml')) return null;

	try {
		return parse(readFileSync('netlify.toml', 'utf-8'));
	} catch (err) {
		if (err instanceof Error) {
			throw new Error(`Failed to parse netlify.toml: ${err.message}`, { cause: err });
		}
		throw err;
	}
}

/**
 * Writes the Netlify Frameworks API config file
 * https://docs.netlify.com/build/frameworks/frameworks-api/
 * @param {{ builder: import('@sveltejs/kit').Builder }} params
 */
function write_frameworks_config({ builder }) {
	// https://docs.netlify.com/build/frameworks/frameworks-api/#headers
	/** @type {{ headers: Array<{ for: string, values: Record<string, string> }> }} */
	const config = {
		headers: [
			{
				for: `/${builder.getAppPath()}/immutable/*`,
				values: {

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Read the underlying err.message/cause to find the offending line and fix the TOML syntax
  2. Validate netlify.toml with a TOML linter or `npx netlify-cli` before building
  3. Temporarily delete netlify.toml to confirm it is the parse failure source, then rebuild it cleanly

Example fix

// before (netlify.toml)
[build]
publish = "build"
functions = 'functions" // broken quote
// after
[build]
publish = "build"
functions = "functions"
Defensive patterns

Strategy: try-catch

Validate before calling

import { parse } from '@iarna/toml';
import { readFileSync, existsSync } from 'node:fs';
if (existsSync('netlify.toml')) parse(readFileSync('netlify.toml', 'utf-8')); // throws early if invalid

Try / catch

try {
  await vite.build();
} catch (e) {
  if (e.message.startsWith('Failed to parse netlify.toml')) {
    console.error('TOML syntax error:', e.cause?.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the Netlify adapter build with a netlify.toml in the project root that the @iarna/toml parser cannot parse (syntax error, unquoted strings with special chars, bad indentation, duplicate keys).

Common situations: Hand-edited netlify.toml with a missing quote or wrong indentation; merge conflicts partially resolved; copying config with smart quotes from documentation or chat.

Understand the failure class

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/8be7e280b18b213a. Report an issue: GitHub.