-1

I try to use express in my application.

import express from 'express';

So I added it to package.json.

  "dependencies": {
    "express": "^4.17.1",
    "express-graphql": "^0.9.0",

Executed yarn. But still I get an error when starting yarn. Do you know why?

<code>enter image description here</code>

tk421
  • 5,775
  • 6
  • 23
  • 34
János
  • 32,867
  • 38
  • 193
  • 353
  • Possible duplicate of [Importing node.js module - SyntaxError: Unexpected identifier](https://stackoverflow.com/questions/55002755/importing-node-js-module-syntaxerror-unexpected-identifier) – Peter Aug 27 '19 at 13:20
  • either switch to `const express = require('express')` or read the above article to setup a compilation step – Peter Aug 27 '19 at 13:21

2 Answers2

0

const express = require('express');

h11
  • 108
  • 1
  • 13
0

The reason it doesn't work is Node doesn't support ES6 imports yet. This link discribes how to enable imports for Node. Another recommendation would be to use require.

const express = require('express');
MartinKT
  • 23
  • 1
  • 5