Skip to content

fix(types): add missing SVG module declarations to resolve compiler errors#1212

Open
subbareddypalagiri wants to merge 1 commit into
f:mainfrom
subbareddypalagiri:fix-svg-types
Open

fix(types): add missing SVG module declarations to resolve compiler errors#1212
subbareddypalagiri wants to merge 1 commit into
f:mainfrom
subbareddypalagiri:fix-svg-types

Conversation

@subbareddypalagiri

@subbareddypalagiri subbareddypalagiri commented Jun 24, 2026

Copy link
Copy Markdown

Description

When running the strict TypeScript compiler (npx tsc --noEmit), the build pipeline throws TS2307: Cannot find module and TS2322 type assignability errors whenever .svg files are imported (e.g., src/components/layout/footer.tsx, src/app/docs/self-hosting/page.tsx). Next.js requires explicit module declarations for static assets like SVGs to prevent compiler crashes during strict validation.

The Fix

  • Added a global src/types/svg.d.ts module declaration file.
  • Defined *.svg to export as any, satisfying the Next.js <Image src={...} /> component requirements.
  • The tsconfig.json correctly picks up the new declarations via the existing **/*.ts include directive.

Type of Change

  • Bug fix
  • Documentation update
  • Other (please describe):

⚠️ Want to Add a New Prompt?

Please don't edit prompts.csv directly!

Instead, visit prompts.chat and use the prompt editor to add your new prompt.

Added a global TypeScript module declaration for *.svg files so SVG imports are recognized during strict type checking.

This resolves the compiler errors caused by importing SVGs in components/pages that use them with Next.js image handling, without requiring changes to existing tsconfig.json includes.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new TypeScript ambient module declaration file src/types/svg.d.ts is added. It declares module "*.svg" with a default export typed as any, allowing TypeScript to accept SVG file imports without type errors.

Changes

SVG Type Declaration

Layer / File(s) Summary
SVG ambient module declaration
src/types/svg.d.ts
Adds a declare module "*.svg" block that exports a default any-typed value, enabling TypeScript to resolve SVG file imports.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding SVG module declarations to fix TypeScript compiler errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/types/svg.d.ts`:
- Line 2: The SVG module declaration is currently widening imported SVGs to any,
which removes type safety for consumers like footer and self-hosting page
components. Update the module declaration in svg.d.ts to use the concrete SVG
import type that matches how the assets are actually consumed, and keep the
exported shape aligned with those usages so imports remain strongly typed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ff007f4b-ac9b-4055-9224-c6eb7cff2ce5

📥 Commits

Reviewing files that changed from the base of the PR and between aa69d53 and b481b2a.

📒 Files selected for processing (1)
  • src/types/svg.d.ts

Comment thread src/types/svg.d.ts
@@ -0,0 +1,4 @@
declare module "*.svg" {
const content: any;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the SVG type declaration and nearby files/usages.
git ls-files 'src/types/svg.d.ts' 'src/**/*.{ts,tsx}' 'messages/*.json' | sed -n '1,200p'

printf '\n--- src/types/svg.d.ts ---\n'
cat -n src/types/svg.d.ts

printf '\n--- SVG import usages ---\n'
rg -n --glob 'src/**/*.{ts,tsx}' --glob '!**/*.d.ts' --glob '!**/node_modules/**' '\.svg(["'\'']|$)|from [^;]*\.svg|import .*\.svg' src || true

Repository: f/prompts.chat

Length of output: 5555


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find any file patterns or config suggesting SVG imports are treated specially.
rg -n --glob 'src/**/*.{ts,tsx,js,jsx,mts,cts}' --glob '*.d.ts' --glob 'next.config.*' --glob 'tsconfig*.json' \
  'StaticImageData|declare module .*\.svg|svgRuntime|`@svgr`|svgr|next/image|Image ' . || true

Repository: f/prompts.chat

Length of output: 8259


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the relevant declaration file with line numbers if present.
if [ -f src/types/svg.d.ts ]; then
  cat -n src/types/svg.d.ts
fi

Repository: f/prompts.chat

Length of output: 255


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect package/tooling versions for Next.js/TypeScript/SVG handling clues.
if [ -f package.json ]; then
  cat package.json
fi

Repository: f/prompts.chat

Length of output: 4117


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Probe whether StaticImageData is exported/imported anywhere in the repo.
rg -n --glob 'src/**/*.{ts,tsx,d.ts}' 'StaticImageData' . || true

Repository: f/prompts.chat

Length of output: 152


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- src/types/svg.d.ts ---'
if [ -f src/types/svg.d.ts ]; then
  cat -n src/types/svg.d.ts
else
  echo 'missing'
fi

echo
echo '--- SVG-related config/usages ---'
rg -n --glob 'src/**/*.{ts,tsx,d.ts,js,jsx,mts,cts}' --glob 'next.config.*' --glob 'tsconfig*.json' \
  'declare module .*\.svg|StaticImageData|`@svgr`|svgr|dangerouslyAllowSVG|next/image|from .*\.svg|import .*\.svg' . || true

Repository: f/prompts.chat

Length of output: 1822


🌐 Web query:

Next.js SVG import type StaticImageData string module declaration next/image svg default export

💡 Result:

In Next.js, importing an SVG file behaves differently depending on your configuration [1][2]. By default, Next.js does not treat SVG files as StaticImageData objects (which are reserved for formats like PNG, JPG, or WebP) [3][1]. Instead, standard SVG imports often require third-party tools like @svgr/webpack to function as React components or as string paths [4][1][5]. If you are encountering a TypeScript error expecting a string but receiving a StaticImageData object (or vice versa), it is usually due to conflicting type declarations or custom webpack/turbopack configurations [3][6][7]. To use SVGs in Next.js, follow one of these common approaches: 1. Use next/image for static assets Place your SVG in the public directory and reference it by its string path [1]. Icon 2. Use @svgr/webpack to import as a React Component If you want to import an SVG and use it as a component, configure your next.config.js/ts to use @svgr/webpack [8][5]. // next.config.js module.exports = { webpack(config) { config.module.rules.push({ test: /.svg$/i, issuer: /.[jt]sx?$/, use: ['@svgr/webpack'], }); return config; }, }; 3. Handle Dual-Purpose Imports (Component + URL) To use an SVG both as a React component and as an image source (for next/image), you can use resource queries in your webpack configuration [6]. // next.config.js module.exports = { webpack(config) { config.module.rules.push({ test: /.svg$/i, issuer: /.[jt]sx?$/, resourceQuery: { not: [/url/] }, use: ['@svgr/webpack'], }); config.module.rules.push({ test: /.svg$/i, resourceQuery: /url/, type: 'asset/resource', }); return config; }, }; // Typescript declaration (e.g., in next-env.d.ts or svg.d.ts) declare module ".svg?url" { const src: string; export default src; } declare module ".svg" { import React = require("react"); const ReactComponent: React.FC<React.SVGProps>; export default ReactComponent; } This allows you to import the component version normally (import Logo from './logo.svg') or the string path version by appending a query (import logoUrl from './logo.svg?url') [6].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- next.config.ts ---'
if [ -f next.config.ts ]; then
  cat -n next.config.ts
fi

echo
echo '--- any other svg declarations ---'
rg -n --glob '*.d.ts' 'declare module ".*\.svg' . || true

echo
echo '--- tsconfig files ---'
git ls-files 'tsconfig*.json' | sed -n '1,50p'
for f in $(git ls-files 'tsconfig*.json'); do
  echo
  echo "--- $f ---"
  cat -n "$f"
done

Repository: f/prompts.chat

Length of output: 4948


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- src/types/svg.d.ts context ---'
cat -n src/types/svg.d.ts

echo
echo '--- imports of DeepWikiIcon / Context7Icon ---'
rg -n 'DeepWikiIcon|Context7Icon' src || true

Repository: f/prompts.chat

Length of output: 1182


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- next.config.ts ---'
cat -n next.config.ts

Repository: f/prompts.chat

Length of output: 3883


Avoid any in src/types/svg.d.ts
The SVG module declaration currently widens every .svg import to any, which weakens strict typing across components like src/components/layout/footer.tsx and src/app/docs/self-hosting/page.tsx. Use the concrete import type that matches the actual SVG usage instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types/svg.d.ts` at line 2, The SVG module declaration is currently
widening imported SVGs to any, which removes type safety for consumers like
footer and self-hosting page components. Update the module declaration in
svg.d.ts to use the concrete SVG import type that matches how the assets are
actually consumed, and keep the exported shape aligned with those usages so
imports remain strongly typed.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant