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;
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
add a comment |
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
what does your babel config look like?
– miyu
Mar 24 at 23:31
add a comment |
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
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
javascript node.js ecmascript-6
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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
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 yourroot/
directory and call a script that is in sayroot/folderA
and that script imports something fromroot/folderB
then thejs
file fromfolderB
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 24 at 23:34
jsdeveloperjsdeveloper
2,261158
2,261158
add a comment |
add a comment |
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
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 yourroot/
directory and call a script that is in sayroot/folderA
and that script imports something fromroot/folderB
then thejs
file fromfolderB
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
add a comment |
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
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 yourroot/
directory and call a script that is in sayroot/folderA
and that script imports something fromroot/folderB
then thejs
file fromfolderB
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
add a comment |
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
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
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 yourroot/
directory and call a script that is in sayroot/folderA
and that script imports something fromroot/folderB
then thejs
file fromfolderB
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
add a comment |
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 yourroot/
directory and call a script that is in sayroot/folderA
and that script imports something fromroot/folderB
then thejs
file fromfolderB
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
what does your babel config look like?
– miyu
Mar 24 at 23:31