简体   繁体   English

jspm / jQuery / TypeScript - 模块“jquery”没有默认导出

[英]jspm / jQuery / TypeScript - module “jquery” has no default export

I'm trying to bootstrap a web app using TypeScript and jspm & system.js for module loading. 我正在尝试使用TypeScript和jspm&system.js来引导Web应用程序以进行模块加载。 I'm not getting very far. 我没有走得太远。 After installing jspm, and using it to install jQuery: 安装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将无法编译,因为“Module'jquery'没有默认导出。

The generated config.js has the correct mapping: "jquery": "npm:jquery@2.2.0" 生成的config.js具有正确的映射:“jquery”:“npm:jquery@2.2.0”

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";import * as $ from "jquery";

or import named exports: import { ajax, css } from "jquery"; 或者import { ajax, css } from "jquery";导入命名导出: import { ajax, css } from "jquery";

If you are using visual studio , update the typescript plugin. 如果您使用的是visual studio ,请更新typescript插件。

To obtain the latest version for visual studio 2017, go there 要获得2017年Visual Studio的最新版本, 请去那里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM