Source: https://mokxi.com/errors/does-not-name-a-type
Updated: 2026-11-16

Home / Errors
Arduino build error

# error: 'Servo' does not name a type

The compiler expected a type, such as int, String or Servo, and the word it found is not one it knows.

Try the fixed sketch in Mokxi See the causes

- Build error
- 4 common causes
- Seen 725 times in failed builds on Mokxi in the 30 days to November 16, 2026.

The message

## What the Arduino IDE prints

Output window

It happens when a library is not included, when a statement sits outside every function, when a type is spelled with the wrong capital, and when a type is used above the line that defines it.

Mokxi's compiler, clang, words it as unknown type name 'Servo'.

Causes

## The 4 usual causes with the fix

### 1A library class without its #include

Servo is a class that the Servo library declares. The sketch has to include the library before the first line that makes a Servo.

Broken

Fixed

Mokxi’s build tab says: Servo comes from a library the sketch does not include. Add #include <Servo.h> at the top of the sketch.

Try this fix in Mokxi

### 2A statement outside every function

Between functions you can declare variables and objects. You cannot run a call. A line such as Serial.begin(9600); at the top of the file reads to the compiler like the start of a declaration, so it asks what type Serial is.

Broken

Fixed

Mokxi’s build tab says: Serial is used as a type, but nothing declares it.

Try this fix in Mokxi

### 3A type spelled with the wrong capital

Arduino's text type is String with a capital S. The lowercase string is not a type in an Arduino sketch.

Broken

Fixed

Mokxi’s build tab says: Arduino spells it String, not string. Names in C++ must match exactly, capital letters included.

Try this fix in Mokxi

### 4A struct used above the line that defines it

The compiler has to see struct Point before it can read a line that makes a Point. Move the definition to the top, above everything that uses it.

Broken

Fixed

Try this fix in Mokxi

FAQ

## Questions and answers

### What does 'does not name a type' mean in Arduino?

The compiler expected a type name and found a word it has no type for. Usually the library include is missing or a call was written outside a function.

### Why does a missing #include give this error and not "file not found"?

Nothing is wrong with the include line you have. The include line you need is not there at all, so the compiler never learns the type exists.

### Why does 'Serial' not name a type?

The line Serial.begin(9600); sits outside setup() and loop(). Move it into setup().

Next

## More errors and the longer guide

- error: 'ledPin' was not declared in this scope
- fatal error: Servo.h: No such file or directory

The longer guide to this error All Arduino errors
