revolunet / angular-google-analytics

Google Analytics tracking for your AngularJS apps
MIT License
652 stars 179 forks source link

Cannot find module 'angular' in build time browserify #195

Closed ViieeS closed 6 years ago

ViieeS commented 7 years ago

Cannot find module 'angular' from '.../vendors/angular-google-analytics/dist'

I define it like this:

require('./../../vendors/angular-google-analytics/dist/angular-google-analytics.js');

maybe problem with this

(function (root, factory) {
  'use strict';
  if (typeof define === 'function' && define.amd) {
    define(['angular'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('angular'));
  } else {
    factory(root.angular);
  }
}
ViieeS commented 7 years ago

Temporary fix it by remove init checks: promonavigator 2017-01-13 17-36-18

Toxantron commented 7 years ago

Did you load angular before loading this script?

Could you give us a fragment of your index.html or comparable to spot the issue?

ViieeS commented 7 years ago

Yes, angular is first import:

require('angular');
require('./../../vendors/angular-google-analytics/dist/angular-google-analytics.min.js');

Here's snippet of my building task:

return browserify(paths.js, {
  fullPaths: true
})
.bundle()
.pipe(source(bundle + '.js'))
.pipe(gulp.dest(config.bundle))
ViieeS commented 6 years ago

Fixed after migrating from bower to npm

Imports now looks like:

require('angular');
require('angular-google-analytics');

Before was imported from bower directory vendors: require('./../../vendors/angular-google-analytics/dist/angular-google-analytics.min.js');

I think it was some problem with files in bower repo, but because bower is deprecated now I think we can close the task.