我有一个基于React、Node和express的全栈JavaScript应用程序。问题在于,在Node中没有使用default关键字的导出(export without default)无法工作,但在React中却可以正常工作。我的Node和React都共享相同的Babel配置和包。
我已经尝试将 @babel/plugin-proposal-export-default-from 包添加到我的 babel.config.js 文件中,但是在这样做之后,它生成了另一个错误:Unexpected token (25:16) export getMember;。
我甚至试图删除分号。以下是我的 babel.config.js 文件:
我已经尝试将 @babel/plugin-proposal-export-default-from 包添加到我的 babel.config.js 文件中,但是在这样做之后,它生成了另一个错误:Unexpected token (25:16) export getMember;。
我甚至试图删除分号。以下是我的 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"
}
}
以下是出错的代码:
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;