Skip to content

Missing Import Statement

Quick summary

You referenced a function or class that lives in another file but forgot the import statement — the name is undefined.

Why this happens

  • Forgot to add the import line after moving a function to a new file

  • Misspelled the imported name so it does not match the export

  • Used a default export without the correct default import syntax

Minimal example

✗ Broken code
// file: app.js — forgot to import
const result = formatPrice(99); // ReferenceError: formatPrice is not defined
✓ Fixed code
// file: app.js
import { formatPrice } from './utils.js';
const result = formatPrice(99); // works

formatPrice is defined in utils.js but never imported, so it is undefined in app.js. Adding the import makes the name available.

How to diagnose

  • Read the ReferenceError or bundler error naming the missing symbol

  • Search the codebase for the symbol's definition to find its source file

  • Check the import lines at the top of the file for the missing name

How to fix

  • Add the import statement pointing to the file that exports the symbol

  • Match the import style to the export (named vs default)

  • Use the editor's auto-import or quick-fix to add the import

How to prevent

  • Use an IDE with auto-import on save

  • Run the bundler or type checker frequently to catch missing imports early

Related Resources

Related Glossary

Related Lessons

← Back to language