Search code examples
javascriptangularjsnode.jsnode-webkit

Failed to instantiate module, AngularJS + NodeWebkit


I try to make a stand-alone webapp by using Node-Webkit and AngularJS.

I following the AngularJS.org tutorial but i encounter an error when i try to create the angular module.

Error: [$injector:modulerr] Failed to instantiate module hecktelionApp due to:

Error: [$injector:nomod] Module 'hecktelionApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

My project hierarchy is as follows:

root-app-folder
├── index.html
├── package.json
├── js\
│   └── app.js
└── node_modules\
    └── angular\

And here are my files

index.html

<!DOCTYPE html>
<html ng-app="hecktelionApp">
    <head>
        <title>Hecktelion : Legacy</title>
        <script src="js/app.js"></script>
    </head>
    <body>
        <p>Hello world !</p>
    </body>
</html>

app.js

'use strict';

global.document = window.document;

var angular = require('angular');
var hecktelionApp = angular.module('hecktelionApp', []);

package.json

{
  "name": "Hecktelion",
  "main": "index.html",
  "author": "Toxicat <[email protected]>",
  "window": {
    "toolbar": false,
    "width": 1280,
    "height": 1024
  },
  "dependencies": {
    "angular": "^1.3.14"
  }
}

Which i made wrong ?


Solution

  • It looks like window isn't being defined properly with the way angular is required.

    You can wrap your code inside an anonymous function and inject window into it.

    (function() {
        var angular = require('angular');
        var hecktelionApp = angular.module('hecktelionApp', []);
    }).bind(window);