jspm / jQuery / TypeScript - 模块“jquery”没有默认导出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35223977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jspm / jQuery / TypeScript - module "jquery" has no default export
提问by user888734
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:
我正在尝试使用 TypeScript 和 jspm & system.js 来引导 Web 应用程序以进行模块加载。我不会走得很远。安装 jspm 后,并使用它来安装 jQuery:
jspm install jquery
And the basics:
以及基础知识:
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('main');
</script>
main.ts:
main.ts:
import $ from "jquery";
export class Application {
constructor() {
console.log($);
}
}
The TypeScript won't compile because "Module 'jquery' has no default export.
TypeScript 无法编译,因为“模块‘jquery’没有默认导出。
The generated config.js has the correct mapping: "jquery": "npm:[email protected]"
生成的 config.js 具有正确的映射: "jquery": "npm:[email protected]"
回答by Bob Sponge
When the module doesn't have a default export, you can import the complete module as object: import * as $ from "jquery";
当模块没有默认导出时,您可以将完整模块作为对象导入: import * as $ from "jquery";
or import named exports:
import { ajax, css } from "jquery";
或导入命名导出:
import { ajax, css } from "jquery";