Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix ' Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled' in node

I have a full stack javascript application running on React, Node, express. The problem is export without default is not working in node, However, It is working fine in react. Both my node and react share the same babel configs and packages.

I've already tried adding the @babel/plugin-proposal-export-default-from package in my babel.config.js but after doing so, it generates another error

Unexpected token (25:16) export getMember;

I even tried removing the semicolumn

Here's my babel.config.js

    module.exports = {
      "presets": ['@babel/preset-env', '@babel/preset-react'],
      "plugins": [
        [
          "@babel/plugin-proposal-class-properties",
          {
            "loose": true
          }
        ]
      ]

};

Here's my package.json

{
  "name": "dpapi",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon --exec babel-node server.js --ignore dist/",
    "dev": "webpack -wd"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-eslint": "^10.0.1",
    "babel-preset-es2015": "^6.24.1",
    "eslint": "^5.16.0",
    "eslint-plugin-react": "^7.13.0",
    "nodemon": "^1.18.11",
    "webpack-cli": "^3.3.1"
  },
  "dependencies": {
    "@babel/core": "^7.4.4",
    "@babel/node": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/plugin-proposal-export-default-from": "^7.2.0",
    "@babel/preset-env": "^7.4.4",
    "@babel/preset-react": "^7.0.0",
    "@material-ui/core": "^3.9.3",
    "@material-ui/icons": "^3.0.2",
    "axios": "^0.18.0",
    "babel-loader": "^8.0.5",
    "body-parser": "^1.19.0",
    "dropbox": "^4.0.17",
    "ejs": "^2.6.1",
    "express": "^4.16.4",
    "mongoose": "^5.5.7",
    "morgan": "^1.9.1",
    "node-fetch": "^2.5.0",
    "query-string": "^6.5.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-redux": "^7.0.3",
    "react-router-dom": "^5.0.0",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6",
    "webpack": "^4.30.0"
  }
}

Here's my code where the error is occuring

import dbx from '../dropbox';

const getMember = async (req, res, next) => {

    try{


        res.status(201).json({
            message: "Account created"
        });



    } catch(error){
        console.log(error)
        res.status(500).json({
            error: error
        });
    }

}

export getMember;
like image 636
Waeez Avatar asked May 18 '19 06:05

Waeez


1 Answers

You should use export default getMember or export { getMember } or export const getMember = async....

See: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

like image 195
Tameem Safi Avatar answered Sep 23 '22 00:09

Tameem Safi