question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala.js 1.3.1 with scalajs-bundler breaks Circe

See original GitHub issue

See the following repository for full example: https://github.com/kamilkloch/x-monitor-webpack.git

sbt
project frontend
fastOptJS / webpack

Open frontend/index-dev.html, show console.

With Scala.js 1.3.1 web console reads

{
   "name" : "Bob"
}
io.circe.FailedCursor@1
Left(DecodingFailure(Attempt to decode value on failed cursor, List(DownField(name))))

With Scala.js 1.3.0 it works:

{
  "name" : "Bob"
}
io.circe.cursor.ObjectCursor@1
Right(Bob)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
sjrdcommented, Aug 2, 2021

I found why it only surfaces in scalajs-bundler! The bundle produced by scalajs-bundler doesn’t have

'use strict';

at the top of the file! It has it at the beginning of the Scala.js code, but that comes after the code inserted by the bundler for the “module system”. This means that the whole script loses strict mode, including the Scala.js-related code. If I manually add the 'use strict'; at the top of the file produced by scalajs-bundler, then it also fixes the bug!

That also explains why forcing classes fixes the issue, because the body of JavaScript classes always executes in strict mode.

It does not explain why Scala.js 1.5.0+ fixes the issue. Most likely, because for an arbitrary reason, we do not rely on having strict mode somewhere where we previously relied on it.

It does mean that the root issue is not in this repo, however, and that it can pop up again in the future, at any arbitrary time. We should fix it properly in scalajs-bundler.

1reaction
gzm0commented, Feb 4, 2021

Thinking about this some more, I think we should at lest leave this open and ideally dedicate some time minimizing this. Especially because:

  • We do not know for sure this isn’t a Scala.js issue (or at the very least I’m not convinced we know for sure based on what I read in this issue).
  • If Scala.js + bundler + webpack are affected, we should care, since this isn’t a niche case.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing Scala.js 1.3.1
We are pleased to announce the release of Scala.js 1.3.1! ... as they contain a host of important information, including breaking changes.
Read more >
scalacenter/scalajs-bundler - Gitter
I'm happy with the external JS libraries being bundled to one file and the ScalaJS output to another. It's just the source map...
Read more >
Release Notes · Airframe - wvlet.github.io
This version upgrades Scala.js to 1.10.1, msgpack-core 0.9.3 (JDK17 support). AirSpec 22.7.0 fixes JUnit test report (test-repot.xml) output.
Read more >
Scala.js (@scala_js) / Twitter
native vals and defs, as well as some bug fixes. If you're using scalajs-bundler, make sure to upgrade to v0.18.0.
Read more >
scalajs-bundler - Scaladex
scalajs-bundler Gitter Build Status. Module bundler for Scala.js projects that use NPM packages. Uses npm and webpack under the hood.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found