koa connects to mongodb database time error Unexpected token import, has been introduced into babel
server.js
const db = require("./mongodb/db");
const Koa = require("koa");
const webpack = require("webpack");
const merge = require("webpack-merge");
const KoaRouter = require("koa-router")();
const Monk = require("monk");
const schema = require("./mongodb/schema");
const opn = require("opn");
const config = merge(require("../config/webpack.config.dev"));
const appConfig = require("../app.config");
const currentIP = require("ip").address();
const uri = `http://${currentIP}:${appConfig.appPort}`;
const clientCompiler = webpack(config);
const devMiddleware = webpackDevMiddleware(clientCompiler, {
publicPath: config.output.publicPath,
headers: {"Access-Control-Allow-Origin": "*"},
stats: {
colors: true,
modules: false,
},
noInfo: false,
});
// koa server
const app = new Koa();
// dateBase.connect();
db.connect((err) => {
if (err) throw err;
console.log("success");
});
devMiddleware.waitUntilValid(() => {
// console.log("> Listening at " + uri + "\n");
// opn(uri)
});
//
app.on("error", (err) => {
console.error("Server error: \n%s\n%s ", err.stack || "");
});
app.listen(appConfig.appPort);
schema.js
import mongoose from "mongoose";
const Schema = mongoose.Schema;
const UserModel = new Schema({
name: String,
});
const User = mongoose.model("user", UserModel);
module.exports = {
User
};
.babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"react-hot-loader/babel"
]
}
the front-end page can be introduced with import, but the code on the server side cannot be
because the study is not in-depth, so I don"t know what the problem is. Please give me your advice