尝试在TypeScript中导入i18next时无法加载外部模块 [英] Cannot load external module when trying to import i18next in TypeScript

查看:200
本文介绍了尝试在TypeScript中导入i18next时无法加载外部模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法导入i18next的原因之一是因为i18next.d.ts文件没有

One reason why I can't import i18next is because the i18next.d.ts file does not have

declare module "i18next" {
    export = i18next;
}

最后,

就像jquery.d.ts和knockout.d.ts一样. 它只有

at the end, like jquery.d.ts and knockout.d.ts have. It only has

declare var i18next: I18nextStatic;

因此,当我尝试使用

import i18next = require('i18next'); 

它将驳倒: 无法加载外部模块 模块不能别名为非模块类型

it will barf: Cannot load external module Module cannot be aliased to a non-module type

我不知道为什么绝对类型"项目以这种方式构成d.ts文件. 而且我不知道声明模块是否是一个好的解决方案.

I don't know why Definitely Typed project compose the d.ts file in that way. And I don't know if declare module will be a good solution or not.

请有人帮忙.

推荐答案

您可能需要对i18next库进行Shim,以便RequireJS将其定义为模块.

You probably need to Shim the i18next library so that RequireJS defines it as a module.

在RequireJS网站上有更多信息: http://requirejs.org/docs /api.html#config-shim

There's more info on the RequireJS site here: http://requirejs.org/docs/api.html#config-shim

shim : {
   'i18next' : {
      exports : 'i18next'
    }
}

这篇关于尝试在TypeScript中导入i18next时无法加载外部模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆