Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Creating a module with the same name of the app breaks everything #40

Closed
svallory opened this issue Apr 30, 2014 · 6 comments
Closed

Creating a module with the same name of the app breaks everything #40

svallory opened this issue Apr 30, 2014 · 6 comments

Comments

@svallory
Copy link

Hi, sorry for not being able to point out the exact cause, but it's really easy to reproduce.

$ mkdir docs
$ cd docs
$ yo meanjs
$    ... name: Docs

tested it it works fine, then...

$ yo meanjs:crud-module docs

And it breaks. With the following error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module docs due to:
Error: [$injector:modulerr] Failed to instantiate module users due to:
Error: [$injector:unpr] Unknown provider: $stateProvider
http://errors.angularjs.org/1.2.16/$injec...<omitted>...1) angular.js:78
(anonymous function) angular.js:78
(anonymous function) angular.js:3809
forEach angular.js:323
loadModules angular.js:3775
createInjector angular.js:3715
doBootstrap angular.js:1379
bootstrap angular.js:1394
(anonymous function) application.js:19
trigger angular.js:2509
(anonymous function) angular.js:2780
forEach angular.js:330
eventHandler angular.js:2779

Hope it helps :)

@rschwabco
Copy link
Member

We should probably disallow creating module that has the same name as the app... Sounds like a bad idea to me. Opinions?

@frederik
Copy link

Agreed. In any case it'd be interesting to know the cause tho

@aarosil
Copy link

aarosil commented May 1, 2014

Strange... it worked fine w/ 'fake'. It's something w/ the name 'docs' itself.

@svallory
Copy link
Author

svallory commented May 1, 2014

@aarosil I actually discovered the error when trying to create a module “doctors” inside my app, named Doctors.

As to wether it’s a bad idea or not I’m really not in a place to judge right now. But it made sense to my case and it was really annoying to figure out what the problem was and even more so having to change the name of the app or the model to work around it.

@revdave33
Copy link
Contributor

Just a quick look at the code (I might be wrong). Since the main angular module is set to the app name, it uses the module setter in public/js/config.js. That is where the injector sets up all the dependencies (angular.module('appname', [dependency modules]) . Once a module is set, you need to use the getter version of module to add to that (angular.module('appname')). If you use the setter version again you mess things up (I learned that). So when the meanjs:crud-module yeoman process tries to use the same module name as the the appname, it screws up the injected modules for the overall angular module.

Two options: either prohibit a crud-module with the same name as the app, or return to the original way of naming modules with prepending the appname... mean.core mean.article mean.mean etc. (unless that breaks something in a way I'm not seeing)

With the valid example @svallory gives, I would think we would prefer not preventing the developer from doing what makes sense to them in their project. and going the second route.

@amoshaviv
Copy link
Contributor

@svallory indeed an issue, we'll take care of it in the next version.
@revdave33 you're right, I also prefer the second option.

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

6 participants