Babel NodeJS ES6: SyntaxError: Unexpected token exportUncaught SyntaxError: Unexpected token :I keep getting “Uncaught SyntaxError: Unexpected token o”Using Node.js require vs. ES6 import/exportHow to resolve Mongoose Connect UNKNOWN?babel-loader jsx SyntaxError: Unexpected token“unexpected token import” in Nodejs5 and babel?NodeJS (ES6): SyntaxError: Unexpected token {NodeJS plans to support import/export es6 (es2015) modulesNode.js - SyntaxError: Unexpected token importnpm start run error “var before = prev.prev || ; TypeError: Cannot read property 'prev' of undefined”

Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes

Are athlete's college degrees discounted by employers and graduate school admissions?

Undocumented incompatibility between changes and siunitx?

The best in flight meal option for those suffering from reflux

What is the source of 'Ma'alin bekodesh'?

Is it true that "only photographers care about noise"?

Can you open the door or die? v2

Print "N NE E SE S SW W NW"

Is it advisable to add a location heads-up when a scene changes in a novel?

How to deal with an excess of white-space in a CRM UI?

Why are backslashes included in this shell script?

How can religions without a hell discourage evil-doing?

Purpose of cylindrical attachments on Power Transmission towers

Can a 40amp breaker be used safely and without issue with a 40amp device on 6AWG wire?

Is the first of the 10 Commandments considered a mitzvah?

Can an escape pod land on Earth from orbit and not be immediately detected?

Harley Davidson clattering noise from engine, backfire and failure to start

Is there a radar system monitoring the UK mainland border?

Is fission/fusion to iron the most efficient way to convert mass to energy?

Why didn't all the iron and heavier elements find their way to the center of the accretion disc in the early solar system?

Are skill challenges an official option or homebrewed?

usage of mir gefallen

What is Gilligan's full name?

Is all-caps blackletter no longer taboo?



Babel NodeJS ES6: SyntaxError: Unexpected token export


Uncaught SyntaxError: Unexpected token :I keep getting “Uncaught SyntaxError: Unexpected token o”Using Node.js require vs. ES6 import/exportHow to resolve Mongoose Connect UNKNOWN?babel-loader jsx SyntaxError: Unexpected token“unexpected token import” in Nodejs5 and babel?NodeJS (ES6): SyntaxError: Unexpected token {NodeJS plans to support import/export es6 (es2015) modulesNode.js - SyntaxError: Unexpected token importnpm start run error “var before = prev.prev || ; TypeError: Cannot read property 'prev' of undefined”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I'm trying to use babel to run my NodeJS program, which includes ES6 syntax and exports from the Colyseus library. However, when I run the command:



babel-node server.js


The following error message appears:



export class MyRoom extends colyseus.Room {
^^^^^^

SyntaxError: Unexpected token export


Below is my package.json file:




"name": "app",
"version": "1.0.0",
"description": "a description",
"main": "server.js",
"scripts":
"test": "babel-node server.js",
"build": "babel-node server.js"
,
"author": "henryzhu",
"license": "ISC",
"dependencies":
"actionhero": "^19.1.2",
"colyseus": "^0.9.33",
"easytimer.js": "^2.3.0",
"express": "^4.16.3",
"socket.io": "^2.1.0",
"socketio": "^1.0.0",
"uniqid": "^5.0.3"
,
"devDependencies":
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1"




Below is my server.js file:



var colyseus = require("colyseus");
var http = require("http");
var express = require("express");
var port = process.env.port || 3000;

var app = express();

app.use(express.static("public", dotfiles: 'allow' ));

var gameServer = new colyseus.Server(
server: http.createServer(app)
);

export class MyRoom extends colyseus.Room
// When room is initialized
onInit (options)



gameServer.listen(port);









share|improve this question
























  • what does your babel config look like?

    – miyu
    Mar 24 at 23:31

















2















I'm trying to use babel to run my NodeJS program, which includes ES6 syntax and exports from the Colyseus library. However, when I run the command:



babel-node server.js


The following error message appears:



export class MyRoom extends colyseus.Room {
^^^^^^

SyntaxError: Unexpected token export


Below is my package.json file:




"name": "app",
"version": "1.0.0",
"description": "a description",
"main": "server.js",
"scripts":
"test": "babel-node server.js",
"build": "babel-node server.js"
,
"author": "henryzhu",
"license": "ISC",
"dependencies":
"actionhero": "^19.1.2",
"colyseus": "^0.9.33",
"easytimer.js": "^2.3.0",
"express": "^4.16.3",
"socket.io": "^2.1.0",
"socketio": "^1.0.0",
"uniqid": "^5.0.3"
,
"devDependencies":
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1"




Below is my server.js file:



var colyseus = require("colyseus");
var http = require("http");
var express = require("express");
var port = process.env.port || 3000;

var app = express();

app.use(express.static("public", dotfiles: 'allow' ));

var gameServer = new colyseus.Server(
server: http.createServer(app)
);

export class MyRoom extends colyseus.Room
// When room is initialized
onInit (options)



gameServer.listen(port);









share|improve this question
























  • what does your babel config look like?

    – miyu
    Mar 24 at 23:31













2












2








2


1






I'm trying to use babel to run my NodeJS program, which includes ES6 syntax and exports from the Colyseus library. However, when I run the command:



babel-node server.js


The following error message appears:



export class MyRoom extends colyseus.Room {
^^^^^^

SyntaxError: Unexpected token export


Below is my package.json file:




"name": "app",
"version": "1.0.0",
"description": "a description",
"main": "server.js",
"scripts":
"test": "babel-node server.js",
"build": "babel-node server.js"
,
"author": "henryzhu",
"license": "ISC",
"dependencies":
"actionhero": "^19.1.2",
"colyseus": "^0.9.33",
"easytimer.js": "^2.3.0",
"express": "^4.16.3",
"socket.io": "^2.1.0",
"socketio": "^1.0.0",
"uniqid": "^5.0.3"
,
"devDependencies":
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1"




Below is my server.js file:



var colyseus = require("colyseus");
var http = require("http");
var express = require("express");
var port = process.env.port || 3000;

var app = express();

app.use(express.static("public", dotfiles: 'allow' ));

var gameServer = new colyseus.Server(
server: http.createServer(app)
);

export class MyRoom extends colyseus.Room
// When room is initialized
onInit (options)



gameServer.listen(port);









share|improve this question
















I'm trying to use babel to run my NodeJS program, which includes ES6 syntax and exports from the Colyseus library. However, when I run the command:



babel-node server.js


The following error message appears:



export class MyRoom extends colyseus.Room {
^^^^^^

SyntaxError: Unexpected token export


Below is my package.json file:




"name": "app",
"version": "1.0.0",
"description": "a description",
"main": "server.js",
"scripts":
"test": "babel-node server.js",
"build": "babel-node server.js"
,
"author": "henryzhu",
"license": "ISC",
"dependencies":
"actionhero": "^19.1.2",
"colyseus": "^0.9.33",
"easytimer.js": "^2.3.0",
"express": "^4.16.3",
"socket.io": "^2.1.0",
"socketio": "^1.0.0",
"uniqid": "^5.0.3"
,
"devDependencies":
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1"




Below is my server.js file:



var colyseus = require("colyseus");
var http = require("http");
var express = require("express");
var port = process.env.port || 3000;

var app = express();

app.use(express.static("public", dotfiles: 'allow' ));

var gameServer = new colyseus.Server(
server: http.createServer(app)
);

export class MyRoom extends colyseus.Room
// When room is initialized
onInit (options)



gameServer.listen(port);






javascript node.js ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 23:32







Adam Lee

















asked Mar 24 at 23:31









Adam LeeAdam Lee

999




999












  • what does your babel config look like?

    – miyu
    Mar 24 at 23:31

















  • what does your babel config look like?

    – miyu
    Mar 24 at 23:31
















what does your babel config look like?

– miyu
Mar 24 at 23:31





what does your babel config look like?

– miyu
Mar 24 at 23:31












2 Answers
2






active

oldest

votes


















0














babel-node is presumably expecting the node style module syntax:



module.exports = ...


instead of the es6 style:



export class ...


EDIT:



You might be able to fix it by specifying a .babelrc file like so:




"presets": ["env"]



with package babel-preset-env installed






share|improve this answer






























    0














    Add a config file with the following (.babel.config.js):



    module.exports = 
    presets: [
    '@babel/preset-env'
    ]
    ;


    Then run:



    babel-node --config-file .babel.config.js server.js






    share|improve this answer


















    • 1





      That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

      – cglacet
      Apr 2 at 1:28












    • @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

      – ryanpcmcquen
      Apr 2 at 21:34











    • I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

      – cglacet
      Apr 7 at 15:09











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329589%2fbabel-nodejs-es6-syntaxerror-unexpected-token-export%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    babel-node is presumably expecting the node style module syntax:



    module.exports = ...


    instead of the es6 style:



    export class ...


    EDIT:



    You might be able to fix it by specifying a .babelrc file like so:




    "presets": ["env"]



    with package babel-preset-env installed






    share|improve this answer



























      0














      babel-node is presumably expecting the node style module syntax:



      module.exports = ...


      instead of the es6 style:



      export class ...


      EDIT:



      You might be able to fix it by specifying a .babelrc file like so:




      "presets": ["env"]



      with package babel-preset-env installed






      share|improve this answer

























        0












        0








        0







        babel-node is presumably expecting the node style module syntax:



        module.exports = ...


        instead of the es6 style:



        export class ...


        EDIT:



        You might be able to fix it by specifying a .babelrc file like so:




        "presets": ["env"]



        with package babel-preset-env installed






        share|improve this answer













        babel-node is presumably expecting the node style module syntax:



        module.exports = ...


        instead of the es6 style:



        export class ...


        EDIT:



        You might be able to fix it by specifying a .babelrc file like so:




        "presets": ["env"]



        with package babel-preset-env installed







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 23:34









        jsdeveloperjsdeveloper

        2,261158




        2,261158























            0














            Add a config file with the following (.babel.config.js):



            module.exports = 
            presets: [
            '@babel/preset-env'
            ]
            ;


            Then run:



            babel-node --config-file .babel.config.js server.js






            share|improve this answer


















            • 1





              That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

              – cglacet
              Apr 2 at 1:28












            • @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

              – ryanpcmcquen
              Apr 2 at 21:34











            • I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

              – cglacet
              Apr 7 at 15:09















            0














            Add a config file with the following (.babel.config.js):



            module.exports = 
            presets: [
            '@babel/preset-env'
            ]
            ;


            Then run:



            babel-node --config-file .babel.config.js server.js






            share|improve this answer


















            • 1





              That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

              – cglacet
              Apr 2 at 1:28












            • @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

              – ryanpcmcquen
              Apr 2 at 21:34











            • I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

              – cglacet
              Apr 7 at 15:09













            0












            0








            0







            Add a config file with the following (.babel.config.js):



            module.exports = 
            presets: [
            '@babel/preset-env'
            ]
            ;


            Then run:



            babel-node --config-file .babel.config.js server.js






            share|improve this answer













            Add a config file with the following (.babel.config.js):



            module.exports = 
            presets: [
            '@babel/preset-env'
            ]
            ;


            Then run:



            babel-node --config-file .babel.config.js server.js







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 0:16









            ryanpcmcquenryanpcmcquen

            3,1961329




            3,1961329







            • 1





              That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

              – cglacet
              Apr 2 at 1:28












            • @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

              – ryanpcmcquen
              Apr 2 at 21:34











            • I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

              – cglacet
              Apr 7 at 15:09












            • 1





              That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

              – cglacet
              Apr 2 at 1:28












            • @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

              – ryanpcmcquen
              Apr 2 at 21:34











            • I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

              – cglacet
              Apr 7 at 15:09







            1




            1





            That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

            – cglacet
            Apr 2 at 1:28






            That doesn't seem to work with "@babel/cli": "^7.2.3", "@babel/core": "^7.4.0", "@babel/node": "^7.2.2", "@babel/preset-env": "^7.0.0". I always fail to understand why there are so many ways for doing one such simple thing as transpiling some code in JS.

            – cglacet
            Apr 2 at 1:28














            @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

            – ryanpcmcquen
            Apr 2 at 21:34





            @cglacet, that is a different major version of Babel, have you checked their docs on this? I'm guessing a CLI flag changed between versions.

            – ryanpcmcquen
            Apr 2 at 21:34













            I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

            – cglacet
            Apr 7 at 15:09





            I think I found the problem. If you have your config in your root/ directory and call a script that is in say root/folderA and that script imports something from root/folderB then the js file from folderB doesn't seem to be transpiled correctly (ignored?). That look like a bug to me but maybe I don't understand the responsibility of the config file (I had thought of it as a "project configuration" but apparently that's not how it is supposed to be understood).

            – cglacet
            Apr 7 at 15:09

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329589%2fbabel-nodejs-es6-syntaxerror-unexpected-token-export%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현