我正在尝试使用以下行:
import Clipboard = require('clipboard');
我收到以下错误:
[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.
错误在这一行:
import Clipboard = require('clipboard');
我试过了:
import * as Clipboard from 'clipboard';
和其他一些变化,但无法弄清楚如何解决它。
我正在使用typescript 2.0.0
有任何想法吗?
我和你一样面临同样的问题。
在tsconfig.json文件中,我替换了:
"module": "es6"
同
"module": "commonjs"
并重新启动终端。有效。
我有同样的问题,并改为:
import * as myGlobals from "../globals";
解决了这个问题。 globals.ts
文件位于app
主文件夹中,我正在从子文件夹services
中加载它。
如果您使用的是Angular CLI:我在module
文件中将es2016
的值设置为src/tsconfig.app.json
之后能够编译我的项目。
尝试在tsconfig中将模块设置为commonjs
您可以使用webpack here尝试此示例
更新我的vsCode后我遇到了同样的问题。
只需用"module": "es5"
替换
到tsconfig.app.json中的"module": "commonjs"