无法识别 ES6 - NodeJS 和 WebStorm

Kes*_*vid 4 javascript node.js webstorm typescript ecmascript-6

我一直在谷歌上搜索并到处搜索,但找不到答案。

我只是对 Typescript 有点熟悉。开始在我的 GraphQL NodeJS 服务器上工作,并希望使用 Typescript 进行更安全、更轻松的编码。

需要做的第一件事是将当前的 JS 版本设置为 ES6,所以我做到了。

另外我这样设置tsconfig

{
"compilerOptions": {
    "module": "es6",
    "target": "es6",
    "noImplicitAny": false,
    "outDir": "./build",
    "sourceMap": true
},
"exclude": [
    "node_modules"
]
Run Code Online (Sandbox Code Playgroud)

}

我的 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");
});
Run Code Online (Sandbox Code Playgroud)

当运行这个我得到

语法错误:意外的令牌导入

另外,当悬停时const graphqlOption: graphqlHTTP.OptionsObj我得到

当前 JavaScript 版本不支持类型

请帮忙,我做错了什么?

提前致谢。

编辑:

希望清楚的是,当我使用 simple 时,var express = require('express')我没有得到这个意外的标记,它会移到下一行

截图:

错误、JavaScript 设置和 tsconfig

Vad*_*Vad 5

去:

File -> Settings -> Languages -> JavaScript
Run Code Online (Sandbox Code Playgroud)

并启用 ES6。

  • 正如我在我的问题中提到的。这是我做的第一件事:将 JavaScript 版本更改为 ES6 (2认同)