pbakaus/impeccable · error · Error

Invalid svelte-component source file

Error message

Invalid svelte-component source file

What it means

Thrown by resolveSourceFile when the sourceFile argument is falsy or an absolute path. The library requires a project-relative path so it can contain the resolved file inside the project root; absolute paths are rejected up front to avoid the escape check being bypassed.

Source

Thrown at plugin/skills/impeccable/scripts/live/svelte-component.mjs:444

        const manifest = readManifest(candidate);
        if (manifest?.id === id) return { ...manifest, manifestPath: candidate };
      } catch { /* skip */ }
    }
  }
  return null;
}

export function readManifest(manifestPath) {
  const data = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
  return {
    ...data,
    manifestPath,
  };
}

export function resolveSourceFile(sourceFile, cwd = process.cwd()) {
  if (!sourceFile || path.isAbsolute(sourceFile)) {
    throw new Error('Invalid svelte-component source file');
  }
  const full = path.resolve(cwd, sourceFile);
  const rel = path.relative(cwd, full);
  if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) {
    throw new Error('Svelte-component source file escapes project root');
  }
  if (!fs.existsSync(full)) {
    throw new Error('Svelte-component source file not found: ' + sourceFile);
  }
  return full;
}

function appendCssToSvelteStyle(lines, cssLines) {
  const closeIdx = findLastStyleCloseLine(lines);
  const prepared = ['', ...cssLines.map((line) => (line.trim() === '' ? '' : '  ' + line.trimStart()))];
  if (closeIdx === -1) {
    return [...lines, '', '<style>', ...prepared.slice(1), '</style>'];
  }

View on GitHub (pinned to d14711ae3d)

Solutions

  1. Pass a path relative to the project root, e.g. 'src/lib/Foo.svelte'.
  2. If you hold an absolute path, convert it: path.relative(projectRoot, absPath).
  3. Ensure the argument is non-empty before calling resolveSourceFile.

Example fix

// before
resolveSourceFile('/abs/path/Comp.svelte', cwd);

// after
resolveSourceFile(path.relative(cwd, '/abs/path/Comp.svelte'), cwd);
Defensive patterns

Strategy: validation

Validate before calling

function isValidRelativeSource(sourceFile, cwd) {
  return typeof sourceFile === 'string' && sourceFile.length > 0 && !path.isAbsolute(sourceFile);
}

Type guard

function isRelativeSourcePath(sourceFile) {
  return typeof sourceFile === 'string' && sourceFile.length > 0 && !path.isAbsolute(sourceFile);
}

Try / catch

try {
  resolveSourceFile(sourceFile, cwd);
} catch (err) {
  if (err.message === 'Invalid svelte-component source file') {
    sourceFile = path.relative(cwd, absolutePath);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling resolveSourceFile(undefined), resolveSourceFile(''), or resolveSourceFile('/home/user/proj/src/Foo.svelte'). The first guard trips before any filesystem access.

Common situations: Passing a user-provided absolute path, a config value that resolved to undefined, or a value that came in without normalization.

Related errors


AI-assisted analysis of pbakaus/impeccable@d14711ae3d (2026-08-13). Data as JSON: /api/errors/d5472216705f2040. Report an issue: GitHub.