Carman Babin
Carman Babin

Reputation: 174

typescript error with VS Code. but compiles fine

screen shot of error

When i move my mouse over the red. it says:

Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead.

Like i said it compiles and runs just fine. Its just REALLY annoying having that constantly there.

I am brand new to node.js and typescript. But not brand new to programming, i'v been a C# developer for a long time.

Upvotes: 3

Views: 578

Answers (2)

Carman Babin
Carman Babin

Reputation: 174

I found the answer. I should have just done what it told me to do :)

I replaced

import http = require("http");

with

import * as http from "http"

no more complaining and it all compiles.

I followed the same pattern for the rest of the requires that I had.

Upvotes: 2

basarat
basarat

Reputation: 276333

Import assignment cannot be used when targeting ECMAScript 6 or higher

Open you tsconfig.json and add the following (replacing an existing value if already present... and merging with existing data accordingly):

{
    "compilerOptions" :{
        "target": "es5"
    } 
}

Upvotes: 1

Related Questions