Intellij NodeJs 6.4.0 unexpected token export

I'm using Intellij Idea to create a NodeJs application in ES6.

My node.exe version is version 6.4.0

I created a simple class :

//wNodeClasses.js

'use strict';
export class wsUrl
 {
   constructor()
   {}
 }

I import the module in another file :

require('../../../Root/Libs/Waldata/wsNodeClasses');

When I start the application I always get the error :

d:DevwebDevRootLibsWaldatawsNodeClasses.js:11
export class wsUrl
^^^^^^
SyntaxError: Unexpected token export
   at Object.exports.runInThisContext (vm.js:76:16)
  • I don't use any transpiler , I want to write "pure ES6 code" (I don't want to use Babel or any equivalent)

  • I understand that NodeJs 6.4.0 can interpret directly ES6 code

  • Here is my Node.Exe command line :

    -max-old-space-size=8192 --expose_debug_as=v8debug

  • I am a newbie, I suppose I'm missing something obvious, I googled around and I didn't found an answer


    I finally found the issue. NodeJs 6.4.0 with chrome V8 doesn't support Es6 "export" keyword or syntax.

    I found a work around using

    //Module file
    module.exports=
    class wsUrl
     {
     }
    

    and in the consumer :

    var wsUrl = require('../../../Root/Libs/Waldata/wsNodeClasses');
    ...
    var MyVar = wsUrl new("test");
    

    I'm still searching to have multiple classes in a same Js file (module) and export them


    Thanks for your answer.

    I used a different technic (I assume it's just a matter of personal preference) :

    //In the module module.exports.myClass1=class myClass1{}
    module.exports.myClass2=class myClass2{} 
    
    //In the main file (consumer) 
    var myModule = require('../../../Root/Libs/Waldata/wsNodeClasses'); 
    ... 
    var test=new myModule .wsUrl("param"); 
    

    This works for me with NodeJs 6.4.0 and intellij (or webstorm)

    PS :I'm adding an answer, because I had problems formatting my comment (could not make a "line break"

    链接地址: http://www.djcxy.com/p/92890.html

    上一篇: 调试令人讨厌的SIGILL崩溃:文本段损坏

    下一篇: Intellij NodeJs 6.4.0意外令牌导出