sveltejs/kit · warning
Using $lib/${file} instead of generated .d.ts file
Error message
Using $lib/${file} instead of generated .d.ts file What it means
svelte-package generates .d.ts files into a temp directory and then copies them into the package, applying the $lib alias. If a generated declaration file collides with a handwritten .d.ts the user placed in the source tree (tracked in the `handwritten` set), it warns that the handwritten $lib/<file> version is being used instead of the generated one, so the generated types for that file are discarded.
Source
Thrown at packages/package/src/typescript.js:59
? require.resolve('svelte2tsx/svelte-shims-v4.d.ts')
: require.resolve('svelte2tsx/svelte-shims.d.ts'),
declarationDir: tmp,
tsconfig
});
const handwritten = new Set();
// skip files that conflict with hand-written .d.ts
for (const file of files) {
if (file.name.endsWith('.d.ts')) {
handwritten.add(file.name);
}
}
// resolve $lib alias (TODO others), copy into package dir
for (const file of walk(tmp)) {
if (handwritten.has(file)) {
console.warn(`Using $lib/${file} instead of generated .d.ts file`);
}
let source = fs.readFileSync(path.join(tmp, file), 'utf8');
if (file.endsWith('.d.ts.map')) {
// Because we put the .d.ts files in a temporary directory, the relative path needs to be adjusted
const parsed = JSON.parse(source);
if (parsed.sources) {
parsed.sources = /** @type {string[]} */ (parsed.sources).map((source) =>
posixify(
path.join(
path.relative(
path.dirname(path.join(final_output, file)),
path.dirname(path.join(input, file))
),
path.basename(source)
)
)
);View on GitHub (pinned to 03f1687fe6)
Solutions
- Delete the handwritten .d.ts file if it duplicates a .js/.ts source and let svelte-package generate types
- Rename or move the handwritten declarations to a non-colliding path
- Regenerate types and diff the generated output against the handwritten file to reconcile them
Example fix
// before: both src/lib/utils/index.js and src/lib/utils/index.d.ts exist // after: delete src/lib/utils/index.d.ts and import types from the generated output
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
const generated = 'src/lib/utils/index.d.ts';
if (fs.existsSync(generated) || fs.existsSync(generated.replace('.d.ts', '.js'))) {
console.warn('handwritten .d.ts will shadow generated types');
} Prevention
- Keep at most one type source per module: either .js+.d.ts or .ts
- Delete stale handwritten .d.ts files after TS migration
- Run svelte-package and review warnings in CI
When it happens
Trigger: Running `svelte-package` (emit_dts) when a hand-authored .d.ts file in src/lib has the same output path as a file TypeScript would generate (e.g. src/lib/utils/index.d.ts alongside src/lib/utils/index.js).
Common situations: Manually maintained ambient/handwritten declarations left over after converting JS to TS; intentionally hand-written types that shadow generated ones after adding a matching .js/.ts file; stale .d.ts files committed to the repo before a build-tool migration.
Related errors
- ${keypath} should be a function, if specified
- config.package is no longer supported. See https://github.co
- ${path.relative('.', input)} does not exist
- You need to install TypeScript if you want to transpile Type
- Failed to locate provided tsconfig or jsconfig
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/0eed2994ee7965b9.
Report an issue: GitHub.