0

I try to create veeery simple scala.js app. I was following this tutorial https://www.scala-js.org/doc/tutorial/scalajs-vite.html and I want to decode a json.

Circe https://circe.github.io/circe/ says circe also provides a parser subproject that provides parsing support for Scala.js, with JVM parsing provided by io.circe.jawn and JavaScript parsing from scalajs.js.JSON.

So according to https://circe.github.io/circe/parsing.html I have

import io.circe._
import io.circe.parser._
val myValue = parse(event.data.toString)

and with the following dependencies

"io.circe" %% "circe-core" % "0.14.5",
"io.circe" %% "circe-parser" % "0.14.5",

That gives the following errors

[error] Referring to non-existent class io.circe.parser.package$
[error] Cannot access module for non-module io.circe.parser.package$
[error] Referring to non-existent method 
io.circe.parser.package$.parse(java.lang.String)scala.util.Either

Exactly the same type of error as for JVM only libraries :|

4
  • 4
    I think Scala.js dependencies need to be imported with %%% (triple ampersend), e.g. "io.circe" %%% "circe-core" % "0.14.5" Commented May 9, 2023 at 13:39
  • Yes the three %%% should do the trick here. Note that you can also decode a JSON directly with the browser's JS engine (if your class is "js enough" which means some restrictions), for instance through native-converter: august.nagro.us/scalajs-native-converter.html Commented May 9, 2023 at 19:40
  • Thank you @stefanobaghino, you should post a big answer. Commented May 9, 2023 at 19:45
  • Cool, I didn't have time to check it properly but glad it was correct. :) Commented May 10, 2023 at 9:52

1 Answer 1

2

As mentioned in a comment I wrote and that turned out to be correct, Scala.js modules need to be declared with the %%% operator in your sbt build definition, so your two dependencies would need to be declared as follows:

"io.circe" %%% "circe-core" % "0.14.5",
"io.circe" %%% "circe-parser" % "0.14.5",

You can read more about it here on the documentation of Scala.js.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.