dustinspecker / generator-ng-poly

Yeoman generator for modular AngularJS apps with Gulp and optional Polymer support
MIT License
237 stars 50 forks source link

import and export es6 #360

Open srobledo opened 7 years ago

srobledo commented 7 years ago

Cannot export or import clases when using es6.

Exporting class:

export class authRestService
{
  constructor($resource, env) {
    this.$resource = $resource;
    this.env = env;
  }
}

Importing class and extending:

import {authRestService} from './authrest-service';

(function () {
  'use strict';

  class Auth extends authRestService {
    constructor($resource, env) {
      super($resource, env);
    }

    get() {
      return 'Auth';
    }
  }

  /**
   * @ngdoc service
   * @name components.service:Auth
   *
   * @description
   *
   */
  angular
    .module('components')
    .service('Auth', Auth);
}());

i get the following error on the console,

authrest-service.js:3 Uncaught ReferenceError: exports is not defined(…)(anonymous function) auth-service.js:11 Uncaught ReferenceError: require is not defined(…)(anonymous function)

dustinspecker commented 7 years ago

This has been a pretty big issue for a while. ng-poly does not currently have a module bundler setup, so import/export aren't going to work.

There's a part of me that wants to get Webpack implemented (also would help with the huge Gulp files), but I haven't used Angular in ages.

I'm sorry, but this is probably something that won't be fixed anytime soon. A warning for this ought to be added to the readme.

srobledo commented 7 years ago

@dustinspecker thank you for taking your time to respond, do you suggest any approach (some npm module ect.) so i can resolve this and added to the gulp files? and maybe create a PR for this repo, it would be nice to have it.