angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

Easy error with Webpack, loading modules #2112

Closed arkdelkaos closed 8 years ago

arkdelkaos commented 8 years ago

[QUESTION]

Its going to be easy ;)
I'm having trouble loading modules; I always got this error: Error: [ng:areq] Argument 'module' is not a function, got Object
I know I'm doing it wrong, but I don't know exactly what it's failing.
For example, lets say I want to use [https://github.com/arusahni/ngtweet] npm install --save ngtweet ...then , at webpack.make.js, I add the module to the build entry:

if (TEST) {
    config.entry = {};
  } else {
    config.entry = {
      app: './client/app/app.js',
      polyfills: './client/polyfills.js',
      vendor: [
        'angular',
        'angular-animate',
        'angular-aria',
        'angular-cookies',
        'angular-resource',
        'angular-sanitize',
        'angular-socket-io',
        'angular-ui-bootstrap',
        'angular-ui-router',
        'lodash',
        'ngtweet'
      ]
    };
  }

...then, at app.js:

(...)
import ngtweet from 'ngtweet';
(...)

angular.module('eecrApp', [
    ngCookies, ngResource, ngSanitize, 'btford.socket-io', uiRouter, uiBootstrap, ngtweet,

    _Auth, account, admin, navbar, footer, main, constants, socket, util, rrss
  ])
(...)

Seeing that I cannot make it work with any of the modules I'm installing with npm, what I'm doing wrong?
I'm sure is kind of obvious, but I can't get it to work :(

Item Version
generator-angular-fullstack 4.0.0rc
Node 6.3.1
npm 3.10.3
Operating System OS X 10
Item Answer
Transpiler Babel
Markup Jade
CSS SCSS
Router ui-router
Client Tests Mocha
DB MongoDB
Auth Yup
Awk34 commented 8 years ago

What does importing ngtweet return? (console.log it). I'm guessing it's returning an object with a name property, and is globally registering the Angular module. If so, include ngtweet.name in your dependency array instead.

arkdelkaos commented 8 years ago

Ok, I think I have found it...but...I don't know why! xD

(...)
import 'ngtweet';
import 'angular-ui-scrollpoint';
(...)

angular.module('eecrApp', [
  ngCookies, ngResource, ngSanitize, 'btford.socket-io', uiRouter, uiBootstrap,
  'ui.scrollpoint', 'ngtweet',
(...)

What its the difference between then and now? O__o

Awk34 commented 8 years ago

Look at the signature of angular.module. More directly, you can look at the Angular injector's loadModules function definition.

The first thing it looks for is a module name (String), which would be created by the dependency. Else, if it's a function or an array, it will make providers from them. Else, it runs assertArgFn(module, 'module');, which is where your 'not a function, got object' error comes from. (checks that the arg is a function)

Basically the angular.module requires array parameter takes either strings or functions. Which is returned by importing your module completely depends on the module.

arkdelkaos commented 8 years ago

Ok, understood :) Thanks, as always! :)