如何修复“

时间:2019-05-18 06:39:03

标签: node.js ecmascript-6 babeljs es6-modules babel-loader

我有一个运行在React,Node,Express上的完整堆栈javascript应用程序。 问题是没有export的{​​{1}}在节点中不起作用,但是,在反应中它工作正常。 我的节点和React都共享相同的babel配置和软件包。

我已经尝试在default中添加@babel/plugin-proposal-export-default-from软件包,但是这样做之后,它将生成另一个错误

  

意外的令牌(25:16)导出getMember;

我什至尝试删除分号

这是我的babel.config.js

babel.config.js

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

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"
  }
}

1 个答案:

答案 0 :(得分:0)

您应该使用export default getMemberexport { getMember }export const getMember = async...

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