Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [$injector:modulerr] Failed to instantiate module app.templates #109

Open
tipycalFlow opened this issue Feb 1, 2017 · 3 comments

Comments

@tipycalFlow
Copy link

I can't figure out why my karma.conf.js won't generate the templates module.

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: [  'jasmine', 'requirejs' ],
        files: [
            { pattern: 'public/scripts/app.js', included: false },
            { pattern: 'public/scripts/*.js', included: false },
            { pattern: 'public/scripts/config.js', included: true },
            { pattern: 'test/test-config.js', included: true },
            { pattern: 'public/views/**/*.*', included: false },
            { pattern: 'public/bower_components/**/*.js', included: false },
            { pattern: 'public/scripts/**/*.js', included: false },
            { pattern: 'public/images/**/*.*', included: false },
            { pattern: 'test/directives/**/*.js', included: false
            }
        ],
        plugins: [
            'karma-coverage',
            'karma-jasmine',
            'karma-ng-html2js-preprocessor',
            'karma-requirejs',
            'karma-junit-reporter',
            'karma-chrome-launcher',
            'karma-script-launcher',
            'karma-phantomjs-launcher'
        ],
        preprocessors: {
            '**/*.html': ['ng-html2js']
        },
        ngHtml2JsPreprocessor: {
            moduleName: 'app.templates'
        }
    });
};

In my spec's beforeEach method, module('app.templates'); gives me the following error:

Error: [$injector:modulerr] Failed to instantiate module app.templates due to:
Error: [$injector:nomod] Module 'app.templates' 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.
http://errors.angularjs.org/1.4.9/$injector/nomod?p0=app.templates

I can see in my log that html files are being processed at the correct paths:

DEBUG [preprocessor.html2js]: Processing "/Users/<app_path>/public/views/workspace/my-workspace.html".
@rbnzdave
Copy link

rbnzdave commented Feb 7, 2017

Ah cool.,. I thought it was only me.

"karma-ng-html2js-preprocessor": "^1.0.0"

also dumped the karma output to a text file so could view it as its massive, and sure enough, I have files listed when being processed, but no module being created.

Still trying to find decent and concise examples showing how I'm supposed to reference the cached templates anywhere, as window doesnt contain an html object in it either.

** also worth noting that I am dealing with an ng1 app**

@rbnzdave
Copy link

rbnzdave commented Feb 8, 2017

Well, interesting issue discovered, the output of the plugin is created, but never actually executed by karma, which is why it doesnt work.
Window isnt available in the scope of the pre-processor, so cant call that directly, not sure as to what to actually do.

@evtk
Copy link

evtk commented Aug 29, 2017

exactly in the same boat here, any updates on this since earlier this year?

With debug mode on, I can see the templates are created and are served by the webserver>> serving (cached) <path.to>file.html.js

but get a Error: [$injector:nomod]

edit: seems to be working all of a sudden. Maybe I missed adding *.html to the files property. And I have been checking if the module could be found by doing an var template = angular.module('template')... which turned out to be the wrong direction for testing the functionality in a unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants