NW.js loading files does not seem to provide file’s MIME type.

NWJS Version : v0.25.0-beta1 SDK
Operating System : Windows 10 32-bit (Creators Update)

Expected behavior

This version of NW.js comes with Chromium 61.0.3163.39, which has support for ES6 modules.
One way of utilizing said support is through usage of <script> tag with type=”module”, like so:

<script src="script.js" type="module"></script>

Since this is a part of Chromium and not Node.js it all should work fine, and it kinds does, but not really.

Actual behavior

In fact, the following error appears in the console:

script.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.

Supposedly, the way NW.js loads files does not specify file’s MIME type, leading to this error.
However, starting a local http server which responds with correct MIME types, and changing the script tag to load file through that server like so:

<script src="http://localhost/script.js" type="module"></script>

fixes the problem, and Chromium proceeds with handling modules and running JavaScript like it should.

How to reproduce

  • Create the folowing files in new app’s folder:


<!doctype html>
<script src="script.js" type="module"></script>


/*can be empty, does not matter at all here*/


  "name": "whatever",
  "version": "whatever",
  "main": "index.html"
  • Run NW.js app
  • Right-click in the opened empty app and select ‘Inspect’.
  • There it should be, on the Console tab in Chromium dev tools, the error in all its splendid glory.

To reproduce the MIME type fix do the folowing:

  • Start whatever server, that responds with correct MIME types, so that you can access script.js file through it.
    I ran Node’s http-server on localhost, at port 80.

  • Change the <script> tag to reference the same file on the server.
    In my case it was so:
    <script src="http://localhost/script.js" type="module"></script>

  • Run the NW.js app again, and see that the error is no longer there, and all the code that you might have had in script.js runs just fine.

Author: Fantashit

1 thought on “NW.js loading files does not seem to provide file’s MIME type.

Comments are closed.