Skip to content
This repository was archived by the owner on Apr 5, 2023. It is now read-only.

npm amd version tries to load angular more than once #5

Closed
ghost opened this issue Jun 29, 2015 · 9 comments
Closed

npm amd version tries to load angular more than once #5

ghost opened this issue Jun 29, 2015 · 9 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jun 29, 2015

Look how I did it here: https://github.com/robertbaker/angular-numbro/blob/master/angular-numbro.js

Getting a console message that says trying to load angular more than once and pinned it down to this.

@AndersDJohnson
Copy link
Owner

Related to #4.

@AndersDJohnson
Copy link
Owner

@robertbaker, regarding that code:

76      angularNumbro(angular, require('numbro'));
77      module.exports = 'angularNumbro';

Looks like you're relying on angular already being in the global scope, so probably window.angular? How can you guarantee Angular is already loaded if there is no indication that it's a dependency via a require('angular') as I have done? Wouldn't Browserify not necessarily know to package the scripts in the correct execution order, unless shimmed, e.g. this? Perhaps there is some other convention for Angular modules via npm and/or Browserify of which neither of us was aware?

Also, as a side note, why do you assign a string value to module.exports? Is that some convention or requirement for Browserify? I guess it doesn't matter since you don't really need to export anything, just to register your module with Angular. (Update: Aha, perhaps this)

@ghost
Copy link
Author

ghost commented Jun 29, 2015

I ripped the wrapper from angular-moment (think it was that).
I'm delaying the bootstrap of my app, I'm using systemjs instead of browserify.

I'll add a require angular to mine. Not sure if that will cause angular to load, hope not.

@AndersDJohnson
Copy link
Owner

@robertbaker, please let me know if you find out anything else.

@ghost
Copy link
Author

ghost commented Jul 14, 2015

@adjohnson916 I couldn't resolve this without modifying your wrapper.

IMO it's safe to assume angular is loaded for directives. You can't use an angular directive without angular. You shouldn't run into any script order issues either.

@AndersDJohnson
Copy link
Owner

@robertbaker Probably right. I'll try to reproduce the issue when I can. It may be a bug with Angular - there seems to be a strong convention that node modules can be required multiple times without side effect.

@AndersDJohnson
Copy link
Owner

@robertbaker What version of angular are you using?

I have an example with browersify that's working fine when I require angular 1.4.2 in my main file, despite that the current version of ng-click-select itself, which I also require from my main file, also calls require for angular. See https://adjohnson916.github.io/ng-click-select-node-test/ from https://github.com/adjohnson916/ng-click-select-node-test.

Is your code available anywhere for review?

@ghost
Copy link
Author

ghost commented Sep 17, 2015

Seems to be related to the dependency of npm angular and jspm uses github.

jspm/jspm#1132

@ghost ghost closed this as completed Sep 17, 2015
@AndersDJohnson
Copy link
Owner

Thanks for reporting back, @robertbaker. I don't use jspm, so that would explain it.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant