Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not call Config.resolve in Scalajs #36

Closed
andares opened this issue Jun 17, 2019 · 11 comments
Closed

Could not call Config.resolve in Scalajs #36

andares opened this issue Jun 17, 2019 · 11 comments

Comments

@andares
Copy link

andares commented Jun 17, 2019

[info] Done compiling.
[info] Fast optimizing /bhc/target/scala-2.12/bhc-fastopt.js
[error] Referring to non-existent class java.util.IdentityHashMap

It looks use typeconfig lib to resolve hocon config. There is not IdentityHashMap exists in scala lib, can I find other way to resolve it?

@ekrich
Copy link
Owner

ekrich commented Jun 17, 2019

@andares This is a bug, thanks for reporting. This class is missing in the Scala.js Java library and because all the tests are not run with Scala.js - this bug was not found.

Right now we cannot share tests because we don't have a shared test framework for all three platforms but I would like to find or have a test for this so if you could supply the code you used to create the error it would be helpful.

@andares
Copy link
Author

andares commented Jun 17, 2019

I'm glad to be able to support.

here is my code, I have to say I'm a beginner in scala 😹

package example

import org.ekrich.config._
import scala.io.Source

object Test extends App {
  def parseFile() = {
    // That's not work, need `java.io.File`
    val config = ConfigFactory.parseString("main.conf")
    println(config.resolve)
    // println(config)
  }

  def parseString() = {
    val content = """
_pattern.default.main = "../default/main.conf"

core = {
  version: 0.1
  extends: [
    ${_pattern.default.main}
  ]
}
"""
    val config = ConfigFactory.parseString(content)
    println(config.resolve) // That's crash
    // println(config) // That's ok
  }

  // --> run test
  // parseFile
  parseString
}

here is build.sbt content:

import Dependencies._

ThisBuild / scalaVersion     := "2.12.8"
ThisBuild / version          := "0.1.0-SNAPSHOT"
ThisBuild / organization     := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
  .settings(
    name := "bhc",
    libraryDependencies += scalaTest % Test,
  )

// See https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html for instructions on how to publish to Sonatype.

// sconfig
libraryDependencies += "org.ekrich" %%% "sconfig" % "0.9.+"

// scalajs
enablePlugins(ScalaJSPlugin)
scalaJSUseMainModuleInitializer := true

Talk a little more, at the beginning I thought I could get the best support for hocon in scala. but I found Scala relies heavily on java libraries on the jvm platform. I think scalajs is hard to deal with, may be use js lib by interop is better way 🤣

@ekrich
Copy link
Owner

ekrich commented Jun 17, 2019

Scala.js doesn't have any support for java.io.File so we don't expect that to work but I think you should be able to call resolve but right now Scala.js doesn't have support for IdentityHashMap. I may be able to add it locally at first until we can get it added to Scala.js.

@andares
Copy link
Author

andares commented Jun 18, 2019

That's ok, thank you for the reply 👍

@ekrich
Copy link
Owner

ekrich commented Jul 25, 2019

@andares
Copy link
Author

andares commented Jul 29, 2019

That's great! I have try it again.

@ekrich
Copy link
Owner

ekrich commented Jul 29, 2019

@andares Sorry, I didn't mean to mislead you. I am still working on the Scala.js support for this feature. I just made a test case that works on Scala Native that I can use to test when finishing development on Scala.js. I will close this ticket out once completed and then will need to make a new release for the Scala.js support of this feature.

@andares
Copy link
Author

andares commented Jul 31, 2019

I see, I have parse hocon file with npm lib now, never mind 👌

@ekrich
Copy link
Owner

ekrich commented Jul 31, 2019

I'm sorry you had to resort to that but thanks for reporting and your interest. I have been working on this issue but it requires adding java.util.IdentityHashMap to Scala.js, first locally and then via a PR to Scala.js. It may be working but I just found out how to do resolve myself. I am not a config expert but have spent a bunch of time porting this library.

If you are using Scala.js you can get help here - https://gitter.im/scala-js/scala-js There is another HOCON lib for Scala.js that is very lightweight. https://github.com/akka-js/shocon I hope you keep using Scala.js.

If you would like to discuss further you can find me here as well. https://gitter.im/ekrich/sconfig

@andares
Copy link
Author

andares commented Aug 5, 2019

Thank you for your help indeed. I'll keep trying Scala.js in my project. As compile to js language, use npm lib to resolve problem is also possible 😄 You can close the issue when the work is over.

@ekrich
Copy link
Owner

ekrich commented Nov 22, 2019

Fixed by #57

@ekrich ekrich closed this as completed in 8721a39 Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants