Change MIME Type of application/javascript before migration to Openhab 3.4.4 --> 4.0.0?

  • Platform information:
    • Hardware: Raspberry 4
    • OS: Debian GNU/Linux 11 (bullseye)
    • Java Runtime Environment: OpenJDK 11 (3.4.4) after migration OpenJDK 17
    • openHAB version: 3.4.4


  1. Do I have to change the MIME Types of all my actual openhab 3.4.4 javascript rules before I migrate to Openhab 4.0.0? (application/javascript to application/javascript;version=ECMAScript-5.1)
  2. I installed therefore already the automation add-in JavaScript Scripting (Nashorn) [; as I read that without the add-in all old javascript rules must be migrated to ECMAScript-2021 before migration, is that correct?
  1. No. You can do it before or after. That doesn’t really matter. They won’t work in 3.4.4 with that mime time and they won’t work in 4.0 until they have that mime type.

  2. Mostly correct. 5.2 and 2022 JavaScripts are not compatible without some tweaking. But both can live side-by-side. JavaScript of neither flavor comes with OH in OH 4. Either or both need to be installed. If you do not plan on migrating to version 2022, you need only install the Nashorn add-on.

Note that the name you used implies you are looking at the marketplace version of the add-on. Be sure you install the official version.

And what has not been mentioned here yet is if you are using the JS Transformation, you should remove it before upgrading. And if you are using the JS Transformtion, the easiest thing to do will be to install both JS Scripting add-ons.

1 Like

Thanks Rich,

and one more regarding JS Transformation. You mentioned that I should remove it before upgrade to ver 4.0.0.

So, e.g. for all my outgoing JS transformations in my channel configs, for example JS:setLightState.js
I can keep the code, but rename the transformation script to setLightState.nashornjs and then change the channel configuration to NASHORNJS:setLightState.nashornjs. Is this correct?

That’s one option.

Or you can keep the file names and channel configs and just install the GraalVM JS Scripting add-in in addition to the Nashorn JS Scripting add-on. Nashorn JS Transforms are compatible with GraalVM JS Scripting so they will run just fine on the newer version unchanged.

1 Like

Thanks Rich, I’m now slowly getting an overview of what needs to be done to make the migration to Openhab 4.0.0 as easy as possible.

Also, hopefully your useful marketplace extensions like the Debounce rule will work afterwards as well.
You stated here:

  • A Debounce Group created
  • All the “raw” Items added to the Debounce Group
  • All the “raw” Items have valid “debounce” Item metadata
  • OH 4 the Nashorn add-on needs to be separately installed or change the script type to application/javascript;version=ECMAScript-2021

Shouldn’t this be changed to application/javascript;version=ECMAScript-5.1 like all my other MIME Type aka (application/javascript) rules or does it mean that if I leave the mime type application/javascript in place, that the Nashorn javascript interpreter will kick in?

It feels like there is more to-do’s than former migration from Openhab 2.0 to 3.x.

You should upgrade to the 4.0 version. However that will require the GraalVM add-on to be installed as well as the openhab_rules_tools library to be installed (from the $OH_CONF/automation/js folder run npm install openhab_rules_tools which is discussed in the readme for the 4.0+ version of the rule template.

All but one of my rule templates have been rewritten for GraalJS.

To upgrade, once you are on OH 4, remove the Debounce rule template, refresh the page (I don’t know if that is for sure required but it wouldn’t hurt) and then add it back. It should only show the 4.0+ version of the template after refreshing the page.

It is not super well tested, but I did go to some effort to make those older versions of the rule template work with both Nashorn and GraalJS. Consequently, as long as you have the JS Scripting add-on installed, the 3.x version of the template should work.

But the rewrite version for 4.0+ is a much better implementation with way better error checking and reporting and takes advantage of all the new stuff in GraalJS which makes the code way simpler and easier to maintain.

No, if you leave it as application/javascript the GraalJS add-on will run it. But that should be OK because I wrote those rule templates to work with either engine. But I do strongly recommend upgrading. You existing Items and metadata should work as is. I don’t think I changed anything for that template.

Not in my experience. 2->3 had tons and tons of breaking changes and way more of them were user facing. YMMV. But a major version upgrade is always going to be way more work than a minor version update because major breaking changes are only allowed for major version updates.

1 Like