Using npm modules in Typescript

后端 未结 3 618
陌清茗
陌清茗 2021-01-02 02:16

I would like to use npm module in Typescript project but there is no typings or tsd for this module. When I try use import Module from \'module\' I had an error

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-02 02:56

    I assume your question is related to importing the module

    import Module from 'module'
    

    And not exporting it as you stated. If this is the case your can fall back to plain javascript and require module like this:

    var Module = require('module');
    

    [EDIT]

    Verify that in tsconfig.json you have the following lines in compiler options:

    "compilerOptions": { 
        "moduleResolution": "node",
        "module": "commonjs"
    }
    

    Hope this helps.

提交回复
热议问题