Open Jake6329 opened 1 year ago
[error] Failure on parsing the output of webpack: No content to map due to end-of-input
This appears to be more of a scalajs-bundler
/webpack
build issue. After a failed build, you can try opening a terminal at /Users/jakelim/demos/electron/my-scalajs-app/target/scala-${scalaVersion}/scalajs-bundler/main/
and run npx webpack --config scalajs.webpack.config.js
from there to get the full webpack output.
I've been in a similar situation myself with Scala 3, which prompted me to switch to a Vite
build and I couldn't be happier. I do love scalajs-bundler
and it has served me well in the past, but inevitably sometimes things will break with new Scala/ScalaJS/sbt versions, whereas with Vite
(btw it doesn't have to be Vite - any ESM bundler will do) you're in Node land so anything goes.
I tried the suggested command, but I don't have the necessary knowledge on webpack
to debug the issue. And then I looked up for Vite
and it seems to be a viable alternative to scalajs-bundler
. I'll try it instead. Thanks @nkgm
I hit what seems to be the same issue. Here's the output of the Webpack build that @nkgm suggested:
$ npx webpack --config scalajs.webpack.config.js
/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:298
throw new Error('Invalid mapping: ' + JSON.stringify({
^
Error: Invalid mapping: {"generated":{"line":13609,"column":89},"source":"webpack://https:/raw.githubusercontent.com/japgolly/scalajs-react/v2.1.1/coreGeneric/src/main/scala/japgolly/scalajs/react/ReactCaughtError.scala","original":{"line":12,"column":-1},"name":null}
at SourceMapGenerator_validateMapping [as _validateMapping] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:298:13)
at SourceMapGenerator_addMapping [as addMapping] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-map-generator.js:110:12)
at /Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:351:13
at SourceNode_walk [as walk] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:230:9)
at SourceNode_walk [as walk] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
at SourceNode_walk [as walk] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
at SourceNode_walk [as walk] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
at SourceNode_walk [as walk] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:226:13)
at SourceNode_toStringWithSourceMap [as toStringWithSourceMap] (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/source-map/lib/source-node.js:342:8)
at exports.getSourceAndMap (/Users/matt/repos/personal/scala-3-js-test/js/target/scala-3.2.1/scalajs-bundler/main/node_modules/webpack-sources/lib/helpers.js:20:41)`
Finally got a chance to look into this issue. Was hoping to investigate some more, but this could easily take another week so here's my findings so far.
The sourcemap url's to the published source files are missing a library
segment, eg:
404 -> https://raw.githubusercontent.com/japgolly/scalajs-react/v2.1.1/coreGeneric/src/main/scala/japgolly/scalajs/react/ReactCaughtError.scala
200 -> https://raw.githubusercontent.com/japgolly/scalajs-react/v2.1.1/library/coreGeneric/src/main/scala/japgolly/scalajs/react/ReactCaughtError.scala
You can easily verify this by opening each url in a new brower tab.
A quick workaround would be to disable scalajs sourcemaps:
Compile / fastOptJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
fullOptJS
should work without issues as sourcemaps are disabled by default.
A PR would be trivial replacing this line with s"$flag:$a->$g/v$ver/library/" :: Nil
.
What baffles me still is how this only fails in Scala 3, so I'll be taking a look at the actual sourcemap files next chance I get.
Regarding my previous answer, scalajs-bundler
is not at fault here and still a great tool for the job, even though my personal preference stands.
I had a similar issue and fixed it by bumping the webpack version in the sbt build: webpack / version := "5.76.0"
. Maybe newer webpack versions do not fail if a source map URL returns 404.
I'm new to scalajs-react, and I've set up a minimal project. It works well with Scala 2.13.10 but it fails with Scala 3.2.1 (3.1.3 also shows the same error). When I run the command
sbt "Compile / fastOptJS / webpack"
in order to bundle my app, I get this error messages:Here's my build.sbt and the source code:
If I switch to Scala 2.13.10, this works well as expected. Anyone any idea about the issue?