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

es6 + angu 1.5.5 + babel = exception #14676

Closed
cybermerlin opened this issue May 25, 2016 · 10 comments
Closed

es6 + angu 1.5.5 + babel = exception #14676

cybermerlin opened this issue May 25, 2016 · 10 comments

Comments

@cybermerlin
Copy link

cybermerlin commented May 25, 2016

https://docs.angularjs.org/error/ng/areq?p0=module&p1=not%20a%20function,%20got%20Object

View/Core.js

'use strict';

/**
 * @class Core.View.Core
 * @altClassName CoreView
 * @singleton
 */
class CoreView {
    constructor() {
        console.log('Start Core.View.Core');
        }
}
CoreView.$inject = [];

export default CoreView

Core.js

'use strict';

import CoreView from './View/Core';
import angular from 'angular';


export default angular.module('Core', ['winjs', 'angular-winjs'])
        .controller('Core.View.Core', CoreView)

package.json

    "angular": "^1.5.5",
    "angular-sanitize": "^1.5.5",
    "angular-winjs": "^4.4.0",
    "babel-core": "^6.5.1",
    "babel-loader": "^6.2.2",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.9.0",

webpack.config.js

            {
                // JS LOADER
                // Reference: https://github.com/babel/babel-loader
                // Transpile .js files using babel-loader
                // Compiles ES6 and ES7 into ES5 code
                test: /\.js$/,
                loader: 'babel',
                exclude: /(node_modules|.idea|tests|out|docs)/,
                query: {
                    // https://github.com/babel/babel-loader#options
                    cacheDirectory: true,
                    presets: ['es2015', 'stage-0']
                }
            },
@gkalpak gkalpak added this to the Purgatory milestone May 25, 2016
@gkalpak
Copy link
Member

gkalpak commented May 25, 2016

There is not enough info here to investigate.

What is the context ?
Where is the app run ?
How is it bundled/served ?
What version of Angular are you using ?
What dependencies do you have ?
What does the error stack-trace look like ?
What code is involved ?
How can we reproduce the problem ?

@cybermerlin
Copy link
Author

тут же все написано вроде.
в шапке указана версия
указана какая именно ошибка, а именно: angu жалуется, что ей передали Объект вместо Функции!

предоставил оба файла с классом и подключением к модулю.

Как воспроизвести Вам эту ошибку? - да просто добавить в любой Ваш проект эти два файла...
Вообще я уже отказался от использования этого пакета.
Так что если не хотите помощи - занимайтесь дальше отписками.

@cybermerlin cybermerlin changed the title es6 + angu 1.5.5 = exception es6 + angu 1.5.5 + babel = exception May 26, 2016
@cybermerlin
Copy link
Author

"Error: [$injector:modulerr] Failed to instantiate module function CoreView() due to:
TypeError: Cannot call a class as a function
    at _classCallCheck (http://localhost:8080/dev.js:57808:100)
    at CoreView (http://localhost:8080/dev.js:57817:3)
    at Object.invoke (http://localhost:8080/dev.js:12916:20)

@gkalpak
Copy link
Member

gkalpak commented May 26, 2016

There is (still) not enough info to be sure, but it seems like we are failing to detect you are using a class and not a plain old constructor function.

Could be a browser issue, a transpiler issue or an issue with Angular.
I can't really say without more info, sorry.

@lgalfaso
Copy link
Contributor

Without some extra context, it is hard to know what is going on, so I will make my best guess. I think the issue is the following, Babel here https://github.com/babel/babel/blob/master/packages/babel-helpers/src/helpers.js#L95 is trying to check that their transformed class was called with new. We fail to detect that this is a class (well... because it is not). If this is the case, then adding CoreView.$$ngIsClass = true should fix this.

@thorn0
Copy link
Contributor

thorn0 commented May 28, 2016

@lgalfaso This $$ngIsClass thing hasn't been released yet.

@lgalfaso
Copy link
Contributor

@thorn0 you are right, then the alternatives would be to wait for 1.6 to be out or for Babel not to do this check (do not know if there is a flag to control this or not). One way or another, I think that Angular is doing the right thing here.

Unless somebody has an objection, I would like to close this issue.

@gkalpak
Copy link
Member

gkalpak commented May 29, 2016

Since we are considering removing the "pre-assign bindings on controller instance before instantiating" feature in 1.6 (or making opt-in), it would be a good idea to make it opt-out in 1.5.x (so we could get feedback from developers using it and fix any issues, before making it "mainstream").

That would also solve this issue.

@cybermerlin
Copy link
Author

I'm now is busy with other projects, be sure to accomplish your goal in a couple of days

@gkalpak
Copy link
Member

gkalpak commented Sep 7, 2016

Although support for disabling bindings pre-assignment has landed in master (with #15095), I don't see how this is related to this issue. I don't know what I was thinking in #14676 (comment) 😕

In any case, I agree with #14676 (comment); there is nothing more Angular can do (without risking breaking apps). Closing...

@gkalpak gkalpak closed this as completed Sep 7, 2016
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

4 participants