Cannot load external module when trying to import i18next in TypeScript

雨燕双飞 提交于 2019-12-07 20:25:37

问题


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

declare module "i18next" {
    export = i18next;
}

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

declare var i18next: I18nextStatic;

So when I tried to import in my TypeScript file using

import i18next = require('i18next'); 

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

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.

Someone please help.


回答1:


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

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

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


来源:https://stackoverflow.com/questions/25134054/cannot-load-external-module-when-trying-to-import-i18next-in-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!