出口不打字稿

问题描述:

定义我添加的JQuery在打字稿,但我有此错误:出口不打字稿

Uncaught ReferenceError: exports is not defined

代号TS:

import * as $ from 'jquery' 

    $('.test').click(function(eventObject){ 
     alert('med'); 
    }) 

代码JS:

"use strict"; 
exports.__esModule = true; 
var $ = require("jquery"); 
$('.test').click(function (eventObject) { 
    alert('med'); 
}); 

tsconfig.json :

{ 
    "compilerOptions": { 
     "target": "es5", 
     "module": "es6", 
     "pretty": true, 
     "experimentalDecorators":true 
    }, 

    "files": [ 
     "demo.ts", 
     "typings/index.d.ts" 
    ], 

    "excluse": ["node_modules"] 
} 

如何解决这个bug?

+0

试图您可以发布您tsconfig文件? – rgvassar

+0

你从哪里得到这个错误? – unional

+0

你有安装'@ types/jquery'和'jquery' npm包吗? – msanford

有你陪...

declare var $ :any 


    $('.test').click(function(eventObject){ 
     alert('med'); 
    }) 
+0

错误TS2451:无法重新声明块范围变量'$'。 – devit2017

+0

@ devit2017 Frederico意味着使用'import'语句的_instead_,并将jQuery包含在全局脚本中,以便在'window'中可用。我认为(这是一种常见模式)。 – msanford

+0

@msanford为什么!!!! – devit2017