【问题标题】:Importing momentjs by reference not working (typescript, amd)通过引用导入momentjs不起作用(打字稿,amd)
【发布时间】:2016-08-05 07:13:31
【问题描述】:

我正在尝试了解为什么会这样:

import * as moment from "../Typings/moment";

有效,但是这个:

/// <reference path="../Typings/moment.d.ts" />
import * as moment from "moment";

没有。并抛出错误:cannot fine module 'moment'

后者适用于 react 之类的库,所以我希望它也适用于 momentjs。

我正在使用他们的 git repo 中的类型文件:https://github.com/moment/moment/blob/develop/moment.d.ts

【问题讨论】:

    标签: javascript visual-studio typescript momentjs amd


    【解决方案1】:

    momentjs 的官方文档在导入时是这样说的:

    如果您在导入时刻时遇到问题,请尝试在您的 tsconfig.json 文件的 compilerOptions 中添加 "allowSyntheticDefaultImports": true 。

    【讨论】:

    • 谢谢,但这并不能解决第二种情况,仍然会抛出:cannot find module 'moment'
    猜你喜欢
    • 2016-11-21
    • 2019-02-21
    • 2016-07-13
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多