2

I’m hosting a nodejs project on server, that uses ES6 syntax, and I used babel-cli to compile it. I don't have any problem in my localhost, but when i host it I get this error:

import express from 'express';^^^^^^^SyntaxError: Unexpected identifier

my node version is v10.16.0

package.json:

 { "name": "example", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon ./index.js --exec babel-node -e js" }, "author": "", "license": "ISC", "dependencies": { "bcrypt": "^3.0.2", "express": "^4.16.3", "jsonwebtoken": "^8.4.0", "mongodb": "^3.1.6", "mongoose": "^5.3.1", "nodemailer": "^6.2.1", "nodemon": "^1.18.4", "randomstring": "^1.1.5", "shortid": "^2.2.14" }, "devDependencies": { "babel-cli": "^6.26.0", "babel-preset-env": "^1.7.0", "babel-preset-stage-0": "^6.24.1" } } 

and for .babelrc:

 { "presets": [ "env", "stage-0" ] 

}

import express from 'express'; ^^^^^^^ SyntaxError: Unexpected identifier at Module._compile (internal/modules/cjs/loader.js:721:23) at Object.Module._extensions..js (internal/modules /cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:829:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) 
3
  • Are you host and localhost using the same node version? Commented Jul 31, 2019 at 18:25
  • @zero298 hi, no ,my localhost`s node version is v8.11.1 Commented Jul 31, 2019 at 18:30
  • @zero298 and host's node version is v10.16.0 Commented Jul 31, 2019 at 18:47

1 Answer 1

1

according to this link

https://www.codementor.io/iykyvic/writing-your-nodejs-apps-using-es6-6dh0edw2o

the problem was solved

Sign up to request clarification or add additional context in comments.

1 Comment

How? Can you maybe explain what the issue was and what solved it. The link points to a very long setup tutorial.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.