TypeScript getting error TS2304: cannot find name ' require'

后端 未结 23 2993
Happy的楠姐
Happy的楠姐 2020-11-22 06:00

I am trying to get my first TypeScript and DefinitelyTyped Node.js application up and running, and running into some errors.

I am getting the error \"TS2304: Cannot

23条回答
  •  梦如初夏
    2020-11-22 06:29

    I found the solution was to use the TSD command:

    tsd install node --save
    

    Which adds/updates the typings/tsd.d.ts file and that file contains all the type definitions that are required for a node application.

    At the top of my file, I put a reference to the tsd.d.ts like this:

    /// 
    

    The require is defined like this as of January 2016:

    declare var require: NodeRequire;
    
    interface NodeModule {
        exports: any;
        require: NodeRequireFunction;
        id: string;
        filename: string;
        loaded: boolean;
        parent: any;
        children: any[];
    }
    

提交回复
热议问题