TypeScript getting error TS2304: cannot find name ' require'

后端 未结 23 2646
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:32

    As approved answer didn't mention possibility to actually create your own typings file, and import it there, let me add it below.

    Assuming you use npm as your package manager, you can:

    npm i @types/node --save-dev
    

    Then in your tsconfig file:

    tsconfig.json

    "include": ["typings.d.ts"],
    

    Then create your typings file:

    typings.d.ts

    import 'node/globals'
    

    Done, errors are gone, enjoy TypeScript :)

提交回复
热议问题