[Solved-4 Solutions] Typescript getting error TS2304: cannot find name ' require'
- When we try to get a TypeScript running, we get this error: "TS2304: Cannot find name 'require' " when we attempt to transpile a simple ts node page. The contents of this file are:
- The error is thrown on the var mongoose=require('mongoose') line
- The contents of the typings/tsd.d.ts file are:
- The .d.ts file references were placed in the appropriate folders and added to typings/tsd.d.ts by the commands:
- If you are using TypeScript 2.x you no longer need to have Typings or Definitely Typed installed. Simply install the following package.
- For TypeScript 2.x, there are now two steps:
- Install a package that defines require. For example:
- Tell TypeScript to include it globally in
- The second step is only important if you need access to globally available functions such as require.
- For most packages, you should just use the .import package from 'package' pattern. There's no need to include every package in the tsconfig.json types array above.
- You can
- Also, instead of var mongoose = require('mongoose'), you could try the following
- Instead of: