Search code examples
scalarequirejssbtplayframework-2.3uglifyjs

Out Of Memory Errors with Sbt-Uglify (Play 2.3.7)


I am having issues with the sbt-uglify plugin in my Play application. I have followed the documentation exactly from https://github.com/sbt/sbt-uglify.

In my plugins.sbt I add the plugin:

addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")

In my build.sbt I add uglify to the asset pipeline:

pipelineStages := Seq(uglify, digest, gzip)

I have at least 60 JavaScript files that are being optimized with uglify when I run: sbt start or sbt dist. I begin to see several warnings:

[error] WARN: Dropping unused function argument  
[error] WARN: Dropping unused function argument   
[error] WARN: Dropping unreachable code

I am used to seeing this when I run a similar project with fewer JS files. This continues until it gets to the point of no memory:

[error] java.lang.OutOfMemoryError: unable to create new native thread

I found a similar question being asked about this: Play 2.3.6 Java - OutOfMemory errors w/ sbt-uglify. This didn't seem to be answered and I had already tried increasing my memory limit.

The funny thing is that I can get it to work fine with RequireJS, which should be doing the exact same thing. I should be able to use either, correct?

Has anyone else encountered this problem or know a solution? I am not completely sure if this is an issue with Play, Uglify, or what.

I have added a test example that replicates this issue that you can clone and try for yourself: https://github.com/ascreamingweas/Sbt-Uglify-Test

Your help is appreciated.


Solution

  • I was having the same problem, the sbt-js-engine seems to have solved the issue :

    Just make sure you add the plugin

    ddSbtPlugin("com.typesafe.sbt" % "sbt-js-engine" % "1.0.2")

    Also don't forget to install NodeJS either add

    JsEngineKeys.engineType := JsEngineKeys.EngineType.Node

    or

    export SBT_OPTS="$SBT_OPTS -Dsbt.jse.engineType=Node"