Unexpected token import

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

.
Oct.27,2021

NodeJS's support for ES6 is still in the experimental stage, and it is not turned on by default, so the import syntax is not supported either. Please refer to the documentation on how to open it: https://nodejs.org/api/esm.ht.
if you do not use ES Module, it is also feasible to use Babel. The configuration process is relatively long. I do not know which article you refer to. You can take a look here: https://medium.com/@JedaiSabo.
. I think you may not have used babel-node: during execution

.
./node_modules/.bin/babel-node schema.js

node does not support import syntax. You can introduce modules in the form of require instead;

const mongoose = require('mongoose');

if you use babel, the entry file also cannot use import . The specific configuration method can be used by Baidu. Your babel should be misconfigured, so it was reported incorrectly.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bdaf-4e734.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bdaf-4e734.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?