我正在尝试使用 ES6 语法将 express 导入我的项目,但它一直给我错误:
import express from "express";
SyntaxError: Unexpected identifier
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,发现人们说要添加的地方:
“类型”:“模块”
到我已经完成的 package.json 文件:
...
"description": "Shopping list to learn the MERN stack",
"type": "module",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js"
},
...
Run Code Online (Sandbox Code Playgroud)
But I'm still getting the same issue. I would prefer to use the import ES6 syntax rather than this syntax.
const express = require('express')
Run Code Online (Sandbox Code Playgroud)