FuelLabs/fuels-ts · error · FuelError
CONFIG_FILE_NOT_FOUND
CONFIG_FILE_NOT_FOUND
Error message
TOML file not found:
${dir} What it means
Thrown by getClosestForcTomlDir when its recursive walk from `dir` up to the filesystem root never finds a Forc.toml. The function is used to locate the Forc workspace owning a Sway program; reaching '/' without a hit means no workspace is associated with the supplied path.
Source
Thrown at packages/fuels/src/cli/config/forcUtils.ts:50
predicate = 'predicate',
library = 'library',
}
export const swayFiles = new Map<string, SwayType>();
export const getClosestForcTomlDir = (dir: string): string => {
let forcPath = join(dir, 'Forc.toml');
if (existsSync(forcPath)) {
return forcPath;
}
const parent = join(dir, '..');
forcPath = getClosestForcTomlDir(parent);
if (parent === '/' && !existsSync(forcPath)) {
const msg = `TOML file not found:\n ${dir}`;
throw new FuelError(FuelError.CODES.CONFIG_FILE_NOT_FOUND, msg);
}
return forcPath;
};
export function readForcToml(contractPath: string) {
if (!existsSync(contractPath)) {
throw new FuelError(
FuelError.CODES.CONFIG_FILE_NOT_FOUND,
`TOML file not found:\n ${contractPath}`
);
}
const forcPath = getClosestForcTomlDir(contractPath);
if (!existsSync(forcPath)) {
throw new FuelError(
FuelError.CODES.CONFIG_FILE_NOT_FOUND,View on GitHub (pinned to b3f37c91ac)
Solutions
- Confirm a Forc.toml exists at the workspace root and that the configured path is inside it.
- Fix the path in fuels.config.ts — it should be relative to the config file and within the workspace.
- Create a Forc.toml at the program directory if the project genuinely lacks one.
- Run fuels from the directory containing fuels.config.ts.
Example fix
// before — config points outside workspace contracts: ['../other-project/contract'] // after contracts: ['./contracts/my-contract']
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs';
import { join } from 'path';
function assertInsideWorkspace(dir: string): void {
let cur = dir;
while (true) {
if (existsSync(join(cur, 'Forc.toml'))) return;
const parent = join(cur, '..');
if (parent === cur) throw new Error(`no Forc.toml above ${dir}`);
cur = parent;
}
} Prevention
- Keep all Sway program paths inside the Forc workspace root.
- Run fuels from the workspace root directory.
- Add a lint step that verifies each config path resolves under the workspace.
When it happens
Trigger: Calling getClosestForcTomlDir (transitively, via config resolution) on a directory that is not inside any Forc workspace, or whose path is misconfigured in fuels.config.ts.
Common situations: A contract/predicate/script path in fuels.config.ts points outside the workspace, a typo in the path, a Sway project missing its Forc.toml, or running the CLI from the wrong working directory.
Related errors
- WORKSPACE_NOT_DETECTED
- CONFIG_FILE_NOT_FOUND
- CONFIG_FILE_ALREADY_EXISTS
- BIN_FILE_NOT_FOUND
- Contract not found!
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/41e009c060272032.
Report an issue: GitHub.