sjrd / scalajs-sbt-vite-laminar-chartjs-example

An example of using Scala.js with sbt, Vite, Laminar and Chart.js
Apache License 2.0
88 stars 18 forks source link

Missing source maps for React #1

Closed evbo closed 1 year ago

evbo commented 2 years ago

Wondering if someone else has seen this and found a workaround:

Sourcemap for "/root/git/app/client/target/scala-3.2.0-RC2/client-fastopt/internal-dd54354c54b6cbff7852ab859460a6d93fcdeeba.js"

According to github issues, this should have been resolved on Vite's end with their react plugin, so perhaps could this be due to differences in how scalajs libraries have unusual paths for Vite to resolve?

https://github.com/vitejs/vite/issues/5562

I am using:

"devDependencies": { "@tauri-apps/cli": "1.0.5", "@types/react": "18.0.15", "@types/react-dom": "18.0.6", "@vitejs/plugin-react": "2.0.1", "vite": "3.0.8", "tailwindcss": "3.1.6", "postcss": "8.4.14", "autoprefixer": "10.4.7" }

zetashift commented 2 years ago

I'm running against this too, but using Vite 3:

Sourcemap for "/dev/scala/tyrian-vite-tailwindcss-example/target/scala-3.2.0/app-fastopt/main.js" points to missing source files

But I can't figure out what's going wrong for a long time now... Trying to run this repo gives a similiar source maps error, though this uses Vite 2. @sjrd sorry for the ping, but I actually don't know if this is a Vite or ScalaJS issue? Even if my Main.scala contains:

package app

import scala.scalajs.js.annotation.*

@JSExportTopLevel("TyrianApp")
object App:
  def hello = "hello"

it errors out...

evbo commented 1 year ago

I've since found out that my particular (Linux) browser was expecting source maps in a directory relative to the transpiled js files. I'm not sure why, but found some discord discussions suggesting the following configuration in sbt. Well, it worked for me! This may not work for everyone but please run your devtools in your browser and experiment:

    scalacOptions += {
      val transpiled = baseDirectory.value.toURI.toString
      val to_root = "../../../"
      s"-scalajs-mapSourceURI:$transpiled->$to_root/"
    }