jspm/jQuery/TypeScript-模块"jquery"没有默认导出 [英] jspm / jQuery / TypeScript - module "jquery" has no default export
问题描述
我正在尝试使用TypeScript和jspm&用于模块加载的system.js.我走的不远.安装jspm后,并使用它来安装jQuery:
I'm trying to bootstrap a web app using TypeScript and jspm & system.js for module loading. I'm not getting very far. After installing jspm, and using it to install jQuery:
jspm install jquery
以及基础知识:
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('main');
</script>
main.ts:
import $ from "jquery";
export class Application {
constructor() {
console.log($);
}
}
TypeScript无法编译,因为模块'jquery'没有默认导出.
The TypeScript won't compile because "Module 'jquery' has no default export.
生成的config.js具有正确的映射:"jquery":"npm:jquery@2.2.0"
The generated config.js has the correct mapping: "jquery": "npm:jquery@2.2.0"
推荐答案
当模块没有默认导出时,可以将完整的模块作为对象导入:import * as $ from "jquery";
When the module doesn't have a default export, you can import the complete module as object: import * as $ from "jquery";
或以进口命名的出口:
import { ajax, css } from "jquery";
or import named exports:
import { ajax, css } from "jquery";
这篇关于jspm/jQuery/TypeScript-模块"jquery"没有默认导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!