in Education by
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 questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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

Related questions

0 votes
    I am trying to create a simple node.js app on heroku. Here is app.js: console.log("Starting App" ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a problem, I want to move value of Object[0] nazwa, which is a result of query (let's ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have a problem, I want to move value of Object[0] nazwa, which is a result of query (let's ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I copied and pasted a for-await-of example from MDN and still get an error telling me await is a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I copied and pasted a for-await-of example from MDN and still get an error telling me await is a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am trying to add an if condition; Idea is If I enter the input as print or text with 4 in ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to add an if condition; Idea is If I enter the input as print or text with 4 in ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to add an if condition; Idea is If I enter the input as print or text with 4 in ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to write some stuff in a file using reactJS and nodeJs but it doesnt work. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to write some stuff in a file using reactJS and nodeJs but it doesnt work. Here is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have working (stock) script from node var cluster = require('cluster'); var http = require(' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am using the electron-quick-start app with a windows machine. I have added logging statements in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I am using the electron-quick-start app with a windows machine. I have added logging statements in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    here is my code. var http=require("http"); var fs = require("fs"); var express = require(" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I am using react FineUploaderS3, with params: this.myUploader = new FineUploaderS3({ options: { request: { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
...