TypeScript typings give me “index.d.ts is not a module”

后端 未结 5 747
借酒劲吻你
借酒劲吻你 2020-12-16 09:12

I am getting File node_modules/@types/webrtc/index.d.ts is not a module with this code:

import * as webrtc from \"webrtc\";
const peerConnection1 =          


        
相关标签:
5条回答
  • 2020-12-16 09:27

    No need to import anything, run following:

    1. npm install --save @types/webrtc
    2. update tsconfig.json -

      "types": [ "@types/webrtc" ]

    0 讨论(0)
  • 2020-12-16 09:32

    /// <reference types="@types/<your_types_module>" />

    You may or may not want to do this depending on your build and style needs, but this seems to be the quick (and dirty) fix.

    0 讨论(0)
  • 2020-12-16 09:35

    You probably want to add

    "types": ["webrtc"]
    

    to your tsconfig.json, or less preferrably, to use

    /// <reference types="webrtc" />
    

    in your source files. Here's an example of it in your tsconfig.json:

    {
        "compilerOptions": {
            "target": "es5",
            "sourceMap": true,
            "noImplicitAny": true,
    
            "types": ["webrtc"]
        },
        "exclude": [
            "node_modules"
        ]
    }
    

    This tells TypeScript it should include webrtc declarations in your build

    0 讨论(0)
  • 2020-12-16 09:39

    Another option is to add a new declaration file *.d.ts in your module, i.e.:

    declare module 'my-module';
    
    0 讨论(0)
  • 2020-12-16 09:47

    webrtc is part of the browser; you're trying to import a module. Simply import the (typings) library:

    import "webrtc";
    

    you may need to use "moduleResolution": "node" in the compiler options.

    Alternatively use the "types": ["webrtc"] compiler option and the compiler will automatically load those types up for you.

    0 讨论(0)
提交回复
热议问题