Unexpected token import

  mongodb, question

Koa reported an unexpected tokeninport when connecting to mongodb database. babel has been introduced.

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)
 });
 
 //Error handling
 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"
 ]
 }

Front-end pages can be import, but server-side code cannot
I don’t know what the problem is because I don’t study deeply. Please give your advice.

Node is not supported.importGrammar, you can change it torequireThe way to introduce module;

const mongoose = require('mongoose');

If babel’s is used, the import file is also unavailable.importYes, the specific configuration method can be Baidu. Your babel should be misconfigured, so the report is wrong.