Skip to content
object ... is not a member of package ...

object ... is not a member of package ...

DodaTech 3 min read

The “object … is not a member of package …” error means the Scala compiler cannot find the class, object, or trait at the specified package path.

What It Means

Scala resolves symbols through the package hierarchy. When you write import com.example.utils.MyObject, the compiler looks for com/example/utils/MyObject.class or the corresponding source file on the classpath. If the symbol does not exist at that path — because the package structure is wrong, the library is missing, or the name is misspelled — the compiler reports “not a member of package.”

Why It Happens

  • The class or object doesn’t exist in the package you specified — you have the wrong package name.
  • The library that contains the package is not added as a dependency in build.sbt.
  • You misspelled the package name (case-sensitive, dots vs. slashes).
  • The symbol is defined in a different package than you imported.
  • You are using an outdated version of a library where the symbol was renamed or moved.
  • The source file doesn’t declare the correct package statement.

How to Fix It

1. Verify the exact package name

// ❌ wrong package path
import java.util.List // Java's List is in java.util

// ✅ correct package
import java.util.List
// Or for Scala collections:
import scala.collection.immutable.List

2. Check the library’s documentation

For third-party libraries, confirm the full import path:

// ❌ object Circe is not a member of package io
import io.circe.parser.decode

// ✅ Correct import for circe
import io.circe.parser.decode
// The library dependency must also be in build.sbt:
// libraryDependencies += "io.circe" %% "circe-parser" % "0.14.7"

3. Add the missing dependency to build.sbt

// build.sbt
// ❌ not a member of package org.apache.spark
import org.apache.spark.sql.SparkSession

// ✅ Add the dependency first
libraryDependencies += "org.apache.spark" %% "spark-sql" % "3.5.0"

// Then run: sbt update

4. Check the package declaration in the source file

// File: src/main/scala/com/example/Helpers.scala
// ❌ Wrong package declaration
package com.example.tools
object Helpers { }

// Usage:
// ❌ object Helpers is not a member of package com.example
import com.example.Helpers

// ✅ Fix the package in the source:
package com.example
object Helpers { }

5. Look for renamed or moved symbols in newer versions

// Scala 2.13 moved some symbols:
// ❌ In Scala 2.13:
import scala.collection.mutable.HashMap // no longer exists

// ✅ Use the current path:
import scala.collection.mutable.HashMap
// Actually HashMap still exists — but some types moved:
// scala.collection.immutable.Stream was deprecated in favor of LazyList
What does “not a member of package” mean exactly?
Packages in Scala nest like directories. The compiler walks the package hierarchy: first com, then com.example, then com.example.utils. If at any level the sub-package or symbol doesn’t exist, you get this error. It means the path is broken at some level.
How do I find the correct package for a Scala library?
Check the library’s API docs (e.g., javadoc or Scaladoc), look at example code in the README, or search the source on GitHub. The package is usually listed at the top of every source file as the package declaration.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro