Skip to content
error: not found: value ...

error: not found: value ...

DodaTech 3 min read

The “not found: value” error means the Scala compiler cannot resolve an identifier — a variable, function, or object — at the current position in your code.

What It Means

Scala resolves every identifier against the current scope: local declarations, enclosing class members, imports, and top-level definitions in the same package. When a name doesn’t match any visible declaration, the compiler reports “not found: value [name].” Unlike dynamic languages, this is a compile-time error — the program cannot run until every identifier is resolved.

Why It Happens

  • You mistyped a variable or function name (Scala is case-sensitive).
  • A variable or function was declared in a different scope and is not accessible.
  • An import statement is missing for a definition in another package.
  • You used the wrong case — MyObject vs myObject.
  • The definition is declared later in the same scope (Scala resolves top-down in blocks).
  • A library or object is not on the classpath (missing dependency).

How to Fix It

1. Check for typos and case

// ❌ not found: value helloworld
val helloWorld = "Hello"
println(helloworld)

// ✅ Match the declaration exactly
println(helloWorld)

2. Fix import statements

// ❌ not found: value File
def readFile(path: String): String = File(path).read()

// ✅ Add the required import
import scala.io.Source
def readFile(path: String): String = Source.fromFile(path).mkString

3. Check variable scope

// ❌ not found: value result
def process(): Unit = {
  if (true) {
    val result = 42
  }
  println(result) // result is out of scope here
}

// ✅ Declare before the block
def process(): Unit = {
  val result = if (true) 42 else 0
  println(result)
}

4. Verify package paths for objects and companions

// File: com/example/utils/Helpers.scala
package com.example.utils
object Helpers {
  def greet(name: String): String = s"Hello, $name!"
}

// File: Main.scala
// ❌ not found: value Helpers
object Main extends App {
  println(Helpers.greet("World"))
}

// ✅ Import the object
import com.example.utils.Helpers
object Main extends App {
  println(Helpers.greet("World"))
}

5. Add missing dependencies in build.sbt

If the value comes from an external library:

// build.sbt
// ❌ not found: value Circe (or any library type)
libraryDependencies += "io.circe" %% "circe-core" % "0.14.7"

After adding, run sbt update to fetch the dependency.

6. Use the correct object name for standard library methods

// ❌ not found: value readLine (moved or renamed in Scala 2.13+)
val input = readLine()

// ✅ Use scala.io.StdIn
import scala.io.StdIn
val input = StdIn.readLine()
Does Scala have global variables like Python?
No — every value and variable must be declared in a specific scope (object, class, function, or block). There is no global namespace. Use package objects or top-level definitions (Scala 3) to make values widely accessible.
What’s the difference between “not found: value” and “not found: type”?
“not found: value” means the identifier is expected to be a term (variable, function, object). “not found: type” means it’s expected to be a type name (class, trait, type alias). The distinction helps you narrow down what kind of declaration is missing.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro