Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 is not recognized - NodeJS and WebStorm

I've been googling and searching everywhere and couldn't find an answer.

I'm just a little familiar with Typescript. Started working on my GraphQL NodeJS server and wanted to use Typescript for safer and easier coding.

The first thing needed to be done is set the current JS version to ES6 and so I did.

In addition I set my tsconfig that way:

{
"compilerOptions": {
    "module": "es6",
    "target": "es6",
    "noImplicitAny": false,
    "outDir": "./build",
    "sourceMap": true
},
"exclude": [
    "node_modules"
]

}

my index.js

import * as express from 'express';
import * as graphqlHTTP from 'express-graphql';
import {Schema} from './src/schema/Schema';

const PORT = 3000;

const app = express();

const graphqlOption: graphqlHTTP.OptionsObj = {
  schema: new Schema().getSchema(),
  pretty: true,
  graphiql: true
};

app.use('/graphql', graphqlHTTP(graphqlOption));

app.listen(PORT, ()=> {
  console.log("listening on PORT 3000");
});

When running this I'm getting

SyntaxError: unexpected token import

also, when hovering the const graphqlOption: graphqlHTTP.OptionsObj I get

Types are not supported by the current JavaScript version

Please help, what am i doing wrong?

Thanks in advance.

EDIT:

Wanted it to be clear that when I'm using a simple var express = require('express') I do not get this unexpected token and it moves to the next line

SCREENSHOTS:

Error, JavaScript settings and tsconfig

like image 493
Kesem David Avatar asked Dec 25 '22 02:12

Kesem David


1 Answers

Go to:

File -> Settings -> Languages -> JavaScript

And enable ES6.

like image 51
Vad Avatar answered Jan 13 '23 12:01

Vad