Scala.js with 3.7.0: package scala contains object and package with same name: caps

I am trying to compile my cross platform project with Scala 3.7.0. The project already compiles with fine with 3.6.4. On JVM everything works fine, however I get following issue on Scala.js:

[warn] package scala contains object and package with same name: caps.
[warn] This indicates that there are several versions of the Scala standard library on the classpath.
[warn] The build should be reconfigured so that only one version of the standard library is on the classpath.

While the error does not say it, the issue is with org.scala-lang:scala3-library_3, which is the one that represents caps as a package instead of object.

It seems it goes away when using:

dependencyOverrides += "org.scala-lang" %% "scala3-library" % "3.7.0",

When checking dependencyTree for JS version of my project, the only instance of scala3-library used by dependencies is org.scala-lang:scala3-library_3:3.3.0, used by enumeratum macros. This is no surprise, the libraries creators are encouraged to use LTS version.

How should this be handled properly?

Note: the issue can be reproduced with a simple Scala.js enumeratum project. See GitHub - OndrejSpanel/Enumeratum-Scala3.7: Repro demonstrating issue of mixed Scala3 libraries

Here’s a dedicated issue Build tools issues discovered by binary breakage changes in Scala 3 stdlib · Issue #22890 · scala/scala3 · GitHub and we’re working on resolving this issue.

Typically this kind of issues arise if eviction mechanism picks Scala stdlib (scala3-library_3 artifacts) with version lower then Scala compiler version (scala3-compiler_3 artifacts).

We’ve found out that sometime it can happen when using libraryDependenices := instead of libraryDependenices ++= (probably a hidden stdlib dependency is added by sbt), but it was sometimes also coused by some sbt plugins, eg. the one used by typelevel ecosystem.

One workaround to this problem might be adding explicit dependency scala3-library % scalaVersion.value to ensure that compiler and stdlib are using the same version.

1 Like

My repro is extremely simple. Its sbt is just:

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.7.0"

lazy val root = (project in file("."))
  .enablePlugins(ScalaJSPlugin)
  .settings(
    name := "SandboxJS",
    scalaJSUseMainModuleInitializer := true,
    libraryDependencies += "com.beachape" %%% "enumeratum" % "1.7.6"
  )

The Scala.js sbt plugin is modifing the libraryDependencies under the hood, maybe there is some bug in there.

I confirm it can be fixed with:

libraryDependencies += "org.scala-lang" %% "scala3-library" % scalaVersion.value

or

dependencyOverrides += "org.scala-lang" %% "scala3-library" % scalaVersion.value
1 Like