Webstorm cannot use import to report an error?

/ / index.js

const {query} = require("./sql");
export async function getUser(name){
 let sql = `select name,password from users whername="${name}" `;
  let user = await query(sql)
  return user;
}

/ / server.js

import {getUser} from "./index.js"

error

C:\Users\love4\WebstormProjects\shoppingList\koa\server.js:4
import {getUser} from "./index.js"
^^^^^^

SyntaxError: Unexpected token import

it can be used normally if you use module.exports and require.
is it necessary to configure babel? I didn"t seem to have a problem before I set up ES6 in webstorm

Mar.07,2021

  1. use require;
  2. needs to be used in conjunction with babel.

your server.js is for nodejs, isn't it? how can you use import? Use require.

Menu