Search code examples
ecmascript-6webstorm

WebStorm shows error for import statement


Just started working with ES2015. Using PhpStorm 2016.2. ECMAscript6 is checked.

let i = 1;
export i;

By itself the let statement is fine. I can also make classes, use the fat arrow syntax etc.

However, adding an export statement generates an IDE code error "statement expected" following the let statement as well as the warning "Expression statement is not an assignment or call..." after the import statement.

I understand that to actually run the above sort of code I need a transpiler and loader and what not. But I don't understand why the export statement is not understood by the code inspector? Do I really need a fully configured Babel file watcher and such to get rid of the error message? Seems strange.


Solution

  • According to the MDN export page, webstorm is correct:

    You can do this:

    let i = 1;
    export { i };
    // or use alias
    export { i as whatever };
    

    Or:

    export let i = 1;
    

    Or:

    let i = 1;
    export default i;