angular / angular-hint

run-time hinting for AngularJS applications
362 stars 45 forks source link

Script Error in requirejs environment, cannot load angular-hint. #119

Closed larkin closed 7 years ago

larkin commented 8 years ago

angular-hint does not work when loaded in a requirejs environment, due to an underlying bug in EventEmitter2. The EventEmitter2 bug has been reported twice (https://github.com/asyncly/EventEmitter2/issues/121, https://github.com/asyncly/EventEmitter2/issues/146), with two pull requests provided (https://github.com/asyncly/EventEmitter2/pull/122, https://github.com/asyncly/EventEmitter2/pull/156), but neither solution has been merged at this time.

The bug can be reproduced with the following page, assuming angular-hint is hosted at the absolute path "/hint.js".

<html>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular.min.js"></script>
    <script src="/hint.js"></script>
</body>
</html>

Loading this page will cause a script error when loading hint.js; Uncaught TypeError: EventEmitter2 is not a function.

There was a previous bug report for this issue, https://github.com/angular/angular-hint/issues/116, which was closed without a solution as "we don't use requirejs so it's not our problem." Unfortunately, this prevents anyone who would be using requirejs from using angular-hint. In an ideal "we all play nice" world, Angular-hint's choice of module system should not prevent other projects from using a different module loader. At this time, this bug causes Angular Batarang not to work in requirejs environments.

In the short term, until one of the fixes is merged in EventEmitter2, it should be possible to work around this bug with a small change to the code. All that it takes is changing

var EventEmitter2 = require('eventemitter2').EventEmitter2;

to

var EventEmitter2 = require('eventemitter2');
EventEmitter2 = EventEmitter2.EventEmitter2 || EventEmitter2;

In this file: https://github.com/angular/angular-hint/blob/a5cec66141fea9456fb698925db72d32226a4801/src/modules/hintEmitter.js#L8

Please let me know if there is anything else I can do to help resolve this issue.

Narretz commented 7 years ago

I believe the bug in event emitter has been fixed and we have since updated the dependencies

piotrekkmt commented 6 years ago

Would be good to take a look at your Chrome extensions, some Angular inspectors tend to slow down the network connection so that your app resources could give out errors. AdBlock also being a suspect here.