Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import assignment cannot be used when targeting ECMAScript 2015 modules

I'm trying to use the follwing line:

import Clipboard = require('clipboard'); 

and I get the following error:

   [default] c:\xampp\htdocs\isitperfect\node_modules\angular2-clipboard\src\clipboard.directive.ts:2:0  Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. 

The error is in this line:

import Clipboard = require('clipboard'); 

I tried:

import * as Clipboard from 'clipboard'; 

and some other variations but couldn't figure out how to fix it.

I'm using typescript 2.0.0

Any ideas?

like image 977
TheUnreal Avatar asked Sep 23 '16 15:09

TheUnreal


2 Answers

I was facing the same issue as you.

In the tsconfig.json file I replaced:

"module": "es6" 

with

"module": "commonjs" 

and restarted the terminal. It worked.

like image 97
Shashikant Pandit Avatar answered Oct 23 '22 13:10

Shashikant Pandit


I had the same problem and changing to:

import * as myGlobals from "../globals"; 

fixed the problem. globals.ts file is in the main app folder, and I'm loading it up from subfolder services.

like image 37
KrystianC Avatar answered Oct 23 '22 13:10

KrystianC