小编Tar*_*sam的帖子

如何在 node.js 中使用 es6 模块

我正在尝试使用 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)

node.js express ecmascript-6

3
推荐指数
2
解决办法
7554
查看次数

标签 统计

ecmascript-6 ×1

express ×1

node.js ×1