TypeScript getting error TS2304: cannot find name ' require'

后端 未结 23 2992
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:33

    You can

    declare var require: any
    

    Or, for more comprehensive support, use DefinitelyTyped's require.d.ts

    Also, instead of var mongoose = require('mongoose'), you could try the following

    import mongoose from 'mongoose' // or
    import mongoose = require('mongoose')
    

提交回复
热议问题