【问题标题】:jspm / jQuery / TypeScript - module "jquery" has no default exportjspm / jQuery / TypeScript - 模块“jquery”没有默认导出
【发布时间】:2016-05-15 10:04:51
【问题描述】:

我正在尝试使用 TypeScript 和 jspm & system.js 引导 Web 应用程序以进行模块加载。我不会走得很远。安装jspm后,使用它安装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' 没有默认导出。

生成的 config.js 有正确的映射:"jquery": "npm:jquery@2.2.0"

【问题讨论】:

  • 你试过import * as $ from "jquery";吗?
  • 谢谢你的作品!如果您将其作为答案提交,我可以接受。
  • 这对我有用!

标签: javascript jquery typescript systemjs jspm


【解决方案1】:

当模块没有默认导出时,可以将完整的模块作为对象导入:import * as $ from "jquery";

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

【讨论】:

  • 命名导出不起作用。模块 jquery 没有导出的成员“css”。
  • 别忘了运行:npm install jquery。
  • 如果导出的模块是 CommonJS /AMD/UMD 格式(单个导出成员),TypeScript 文档指出您应该使用 import $ = require("jquery"); typescriptlang.org/docs/handbook/… 这两种方法都有优势吗?
【解决方案2】:

如果您使用的是visual studio,请更新 typescript 插件。

要获取Visual Studio 2017的最新版本,go there

【讨论】:

    猜你喜欢
    • 2017-10-26
    • 2019-09-16
    • 1970-01-01
    • 2021-12-22
    • 2019-12-29
    • 2021-11-24
    • 2017-03-18
    • 2021-11-02
    • 2021-01-09
    相关资源
    最近更新 更多