使用angular cli构建angular2项目时angular2-clipboard中的错误

时间:2016-10-20 10:55:26

标签: angular typescript angular-cli

使用ng build构建angular2项目时出现以下错误

Error in bail mode: [default] /Users/erikwitt/Documents/git/workflow-lights/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.

不确定为什么angular2-clipboard会收到此TypeScript错误。通过ng server,每个思想在开发中都可以正常工作。

我的tsconfig.json如下:

{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
  "es6",
  "dom",
  "es2015.collection"
],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
  "../node_modules/@types"
]
}
}

1 个答案:

答案 0 :(得分:0)

看起来angular2-clipboard不适用于es6模块配置。尝试将其更改为commonjs

{
   "compilerOptions": {
     "declaration": false,
     "emitDecoratorMetadata": true,
     "experimentalDecorators": true,
     "lib": [
       "es6",
       "dom",
       "es2015.collection"
     ],
     "mapRoot": "./",
     "module": "commonjs",
     "moduleResolution": "node",
     "outDir": "../dist/out-tsc",
     "sourceMap": true,
     "target": "es5",
     "typeRoots": [
       "../node_modules/@types"
     ]
   }
}