Hi,
I have an error while compile a js file with ES6 code:
java -jar closure-compiler-v20170409.jar --compilation_level ADVANCED_OPTIMIZATIONS --js_output_file=in.js out.js
```
in.js:3: ERROR - Duplicate let / const / class declaration in the same scope is not allowed.
class Storage {
^^^^^^^
1 error(s), 0 warning(s)
There is conflict name `Storage` with something as I guess.
If I rename, for example, to `_Storage` then compilation ends successfully.
```javascript
"use strict";
class Storage {
}
It's conflicting with the Storage interface. Either wrap your class in an IIFE or rename it.
Hi, is there any solution?
I also just found out the same problem with class Plugin. IIUC these aren't reserved words by the language, why from CC then?
Also is there a list of what else is reserved?
If I do console.log(Storage) in my chrome browser debug console I get
f Storage() { [native code] }
In other words there is already a global variable named Storage, so it isn't safe to define your own class with that name.
Look at the files under https://github.com/google/closure-compiler/tree/master/externs for other names that are already defined.
I meant to say:
"It isn't safe to define your own class named Storage in the global scope."
The problem here is that while using
`import {Plugin} from ./module-x
there is a clear indication that
So I there should be safe way to do this in modules "atleast"
The original example doesn't have an import or export statement in it, so closure-compiler doesn't consider that to be a module.
If you get the same error in a file that does contain either an import or export, I suggest you file a new bug with that example.
Hi @brad4d,
The original example doesn't have an
importorexportstatement in it, so closure-compiler doesn't consider that to be a module.
You pretty much saved my life here :)
But, is there a way to make CC handle all my files as if they were _modules_?
Thanks in advance,
Flo.
You can put an empty export {}; into a file to mark it as a module.
Or you could put "type": "module" in your package.json for marking all your files under that package.json as es6 modules I think. It usually works with node but i haven't tested it with closure compiler
Most helpful comment
The original example doesn't have an
importorexportstatement in it, so closure-compiler doesn't consider that to be a module.If you get the same error in a file that does contain either an
importorexport, I suggest you file a new bug with that example.