spiritworld
spiritworld

Reputation: 143

Windows Universal JavaScript runtime error: 'WinJS' is undefined

I've this app created with cordova/ionic and angularjs. It's using google maps etc. I managed to make a working windows phone 10 build in VS2015 last week and today was going to make release build but surprise mf it just had stopped working for no apparent reason. Started giving me WinJS undefined. My index.html header looks like this before build:

    <script src="cordova.js"></script>
    <script src="js/ionic.bundle.min.js"></script>
    <script src="js/requirejs/require.js"></script>
    <script src="js/app.js"></script>

and while debugging DOM explorer shows this header

    <script src="cordova.js"></script>
    <script src="/www/WinJS/js/base.js"></script>
    <script src="js/ionic.bundle.min.js"></script>
    <script src="ms-appx-web://companyName.appName/www/cordova_plugins.js"></script>
    <script src="js/requirejs/require.js"></script>
    <script src="js/app.js"></script>

so WinJs seems to be included. By inspecting cordova.js with breakpoints I can see that window.WinJS is undefined and script is added with:

    if (!window.WinJS) {
        var scriptElem = document.createElement("script");

        if (navigator.appVersion.indexOf('MSAppHost/3.0') !== -1) {
            // Windows 10 UWP
            scriptElem.src = '/www/WinJS/js/base.js';
     ...}
     scriptElem.addEventListener("load", onWinJSReady);
     document.head.appendChild(scriptElem);

and it still crashes at this point

    var onWinJSReady = function () {
        var app = WinJS.Application;
        .... }

I've seen similar problems here and there but those are for windows phone 8.1. I've no clue anymore what is going on here. My W10 phone updated itself just before the app broke but I doubt it's just coincidence(?)

Upvotes: 3

Views: 1476

Answers (1)

spiritworld
spiritworld

Reputation: 143

Have to answer my own question. The app got running by adding manually WinJS script BEFORE cordova script.

<script src="/www/WinJS/js/base.js"></script>

Upvotes: 3

Related Questions