cocofcb6
cocofcb6

Reputation: 37

How I can put my nodejs code in production with babel?

I configured my babel environment but I have some troubles

My error :

(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose' ^^^^^^^^

SyntaxError: Unexpected identifier

My package.json :

    "babel-cli": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "cron": "^1.7.1",
    "dotenv": "^8.0.0",
    "express": "^4.17.1",
    "mongodb": "^3.3.0-beta2",
    "mongoose": "^5.6.8",
    "nodemailer": "^6.3.0",
    "nodemon": "^1.19.1"
  },
  "scripts": {
    "clean": "rm -rf build && mkdir build",
    "build": "yarn clean && yarn build-babel",
    "build-babel": "babel -d ./build ./src -s",
    "db": "mongod --dbpath ~/data/db",
    "deploy": "yarn build && yarn start",
    "srv:dev": "DEBUG=server:* node_modules/.bin/nodemon src/server.js --exec babel-node --",
    "start": "node ./build/server.js",
    "stop": "pm2 stop ./build/server.js",
    "test": "nodemon --exec babel-node src/server.js"
  },

Upvotes: 1

Views: 797

Answers (1)

vgel
vgel

Reputation: 3335

Seems related to this issue: https://github.com/builderbook/builderbook/issues/97

Their fix was to add --presets=@babel/preset-env after --exec babel-node.

Upvotes: 0

Related Questions