S
S
Sashqa2020-01-27 14:53:58
Node.js
Sashqa, 2020-01-27 14:53:58

Error while importing node js?

The mistake itself

import httpRequest from './httpRequest';
       ^^^^^^^^^^^

SyntaxError: Unexpected identifier


File code
import httpRequest from './httpRequest';
const http = require('http');
const PORT = 3000;

const app = http.createServer((req: any, res: any) => {
  res.end('Hello World!\n');
  httpRequest.sendRequest(idContract, accessToken);
});

app.listen(PORT);
console.log('Сервер запущен на порте 3000');


tsconfig
{
  "compileOnSave": false,
  "compilerOptions": {
    "importHelpers": true,
    "outDir": "./dist/out-tsc",
    "baseUrl": "./",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom",
      "esnext.asynciterable",
      "esnext.array",
      "es2017.object"
    ],
    "module": "es2015"
  }
}

I 'm using the ts-node package.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-01-27
@Sashqa

change "module": "CommonJS"in tsconfig

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question