Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\Dev\webDev\Root\Libs\Waldata\wsNodeClasses.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

like image 746
Henry Kerval Avatar asked Aug 18 '16 23:08

Henry Kerval


1 Answers

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"

like image 129
Henry Kerval Avatar answered Oct 23 '22 18:10

Henry Kerval