sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Module 'ngRaven' 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.

Open mailmrmanoj opened this issue 10 years ago • 23 comments

This is my order of files in karma.conf.js for running karma jasmine uint tests..

files: ['app/bower_components/jquery/dist/jquery.min.js', 'app/bower_components/angular/angular.min.js', 'app/bower_components/raven-js/dist/raven.js', 'app/bower_components/raven-js/plugins/angular.js' ] Event though I included 'app/bower_components/raven-js/plugins/angular.js' I'm getting the error stating the module 'ngRaven' is not available.

mailmrmanoj avatar Mar 14 '16 05:03 mailmrmanoj

+1

mcpawali avatar Mar 14 '16 05:03 mcpawali

Fixed .. http://stackoverflow.com/questions/35980078/module-ngraven-not-available

mailmrmanoj avatar Mar 14 '16 06:03 mailmrmanoj

Is there something actionable we can do here? I'm a bit confused. :)

mattrobenolt avatar Mar 14 '16 15:03 mattrobenolt

Oh, jk, I read the Stackoverflow. It works with the angular-raven package, but not ours.

mattrobenolt avatar Mar 14 '16 15:03 mattrobenolt

Per the current documentation, the sentry angular plugin should now work

https://docs.getsentry.com/hosted/clients/javascript/integrations/angular/

ekaram avatar Mar 29 '16 13:03 ekaram

Might be the directory 'dist' missing in 'app/bower_components/raven-js/plugins/angular.js'?

According to docs [https://docs.getsentry.com/hosted/clients/javascript/integrations/angular/#bower] it should be:

<script src="/bower_components/raven-js/dist/plugins/angular.js"></script>

jacobparra avatar Apr 15 '16 23:04 jacobparra

Following the documentation angular can't find the module for me. The stack overflow solution works for me though.

merrickfox avatar Apr 21 '16 09:04 merrickfox

Might be the directory 'dist' missing in 'app/bower_components/raven-js/plugins/angular.js'?

That would definitely do it.

If somebody here could provide me with a concrete example, I'd be glad to dig into this.

benvinegar avatar Jul 08 '16 21:07 benvinegar

@benvinegar https://plnkr.co/edit/S1Dk9t?p=preview this is a simple sample of the error,

Based on https://github.com/getsentry/raven-js/blob/master/docs/integrations/angular.rst It says: Note that this CDN build auto-initializes the Angular plugin.

But importing only that as the docs says throws an error, please check the log in the plnkr [$injector:nomod] Module 'ngRaven' 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.

Maybe this is just a misinterpretation of the docs?

RobertBaron avatar Sep 01 '16 22:09 RobertBaron

Any news on this? I think the angular plugin only works for CommonJs, since this is actually never called when just including the file. Please fix so we can use the plugin

mebibou avatar Sep 09 '16 03:09 mebibou

Here is the simplest example following your integration page that does not work: https://plnkr.co/edit/M5nt6Y?p=preview

mebibou avatar Sep 09 '16 03:09 mebibou

@RobertBaron @mebibou – in both examples you need to configure Raven before initializing your app. Plugins aren't initialized until Raven.install() is called.

This is in all the documentation examples, for example:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://cdn.ravenjs.com/3.6.1/angular/raven.min.js"></script>
<script>Raven.config('https://<key>@app.getsentry.com/<project>').install();</script>

Although it could be made more explicit that your application script (e.g. app.js) must come afterwards.

benvinegar avatar Sep 09 '16 06:09 benvinegar

Oh ok this actually goes against the Angular way where we usually do this kind of configuration in a module that would require ngRaven, but doing this way makes it impossible.

I think you should specify this in the documentation as it is not specified at all.

mebibou avatar Sep 09 '16 07:09 mebibou

+1

RobertBaron avatar Sep 09 '16 17:09 RobertBaron

See #413, @benvinegar Is it ready to tackle?

Sija avatar Sep 09 '16 17:09 Sija

@Sija – given that people keep tripping up on this, I'm fine with merging. Though I'm worried about the case where someone might have declared Raven before Angular. But at least CDN users need to upgrade manually.

benvinegar avatar Sep 09 '16 17:09 benvinegar

Don't forget to add the bit in bold below

Raven .config('https://@sentry.io/') .addPlugin(Raven.Plugins.Angular) .install();

ashgibson avatar Dec 15 '16 06:12 ashgibson

@theatrain besides that you need to add an override on your package.json if using gulp inject or anything similiar that includes packages dependencies onto your html automatically. The following bellow was my fix since i use gulp-inject

    "overrides": {
        "raven-js" : {
            "main": [
                "dist/raven.js",
                "dist/plugins/angular.js"
            ]
        }
    },

elincognito avatar Jan 23 '17 10:01 elincognito

I found a good workaround for grunt as well since everything was uglified and minified:

My app.js looked like:

'use strict';

angular
  .module('sraApp', [
    'ngRaven'
  ]);

I made another file called raven.js

// redacted sensitive info
Raven
  .config('https://<code>@sentry.io/<myapp>')
  .addPlugin(Raven.Plugins.Angular)
  .install();

And in the index.html instead of inline scripts:

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/raven-js/dist/raven.js"></script>
<!-- endbower -->
<!-- Outside of auto-managed bower, but still inside compile -> vender.js -->
<script src="bower_components/raven-js/dist/plugins/angular.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/raven.js"></script>
<script src="scripts/app.js"></script>
<!-- endbuild -->

Now when I grunt build:dist which uglifies/minifies grunt will optimize my script so the plugin can be registered. Doing inline scripts won't cause the optimization so window.angular won't be right for the plugin to autoload itself.

Overall the flow is as follows (documentation is correct)

  • bring in angular
  • bring in raven
  • bring in raven/plugins/angular.js
  • config/addPlugin/install ngRaven but done properly to take into account uglification/minification

Also another thing to note that most configs can happen later (though you miss tags on any issues during bootstrap)

For example a heroku config loaded after the fact.

'use strict';

angular.module('sraApp')
  .run(function (Raven, HEROKU_APP_ID, HEROKU_APP_NAME, HEROKU_RELEASE_CREATED_AT, HEROKU_RELEASE_VERSION, HEROKU_SLUG_COMMIT, HEROKU_SLUG_DESCRIPTION, NODE_ENV) {
    Raven.setRelease(HEROKU_RELEASE_VERSION);
    Raven.setEnvironment(NODE_ENV);
    Raven.setTagsContext({
      release_date: HEROKU_RELEASE_CREATED_AT,
      git_commit: HEROKU_SLUG_COMMIT,
      slug_description: HEROKU_SLUG_DESCRIPTION,
      application: {
        name: HEROKU_APP_NAME,
        id: HEROKU_APP_ID,
      }
    });
  });

dansabin avatar Feb 26 '17 20:02 dansabin

Any update on this? Also got problems here with our karma test suite.

xeroxoid avatar May 03 '17 15:05 xeroxoid