Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using ES6 with Babel in my project and I am getting an error when I declare one of my const

'use strict';

const APP = window.APP = window.APP || {};
const _ = window._;

APP.personalCard = (function () {

   ...

}());

the error

Uncaught TypeError: Identifier 'APP' has already been declared

and that is the whole file, I don't have that declare anywhere else in that file. But I have declared that var in the top of the other files.

What do you think it should be ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
569 views
Welcome To Ask or Share your Answers For Others

1 Answer

But I have declared that var in the top of the other files.

That's the problem. After all, this makes multiple declarations for the same name in the same (global) scope - which will throw an error with const.

Instead, use var, use only one declaration in your main file, or only assign to window.APP exclusively.
Or use ES6 modules right away, and let your module bundler/loader deal with exposing them as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...