TypeScript error TS2304 cannot find name require

0 votes

I am trying to execute my first TypeScript and DefinitelyTyped Node.js application. But I seem to be running into some errors.

The error that I'm getting is the  "TS2304: Cannot find name 'require' " when I attempt to transpile a simple TypeScript Node.js page. I have read through several other occurrences of this error on Stack Overflow, and I do not think I have similar issues. I am executing this on the shell prompt.

tsc movie.server.model.ts.

The contents of this file are as follows:

'use strict';

/// <reference path="typings/tsd.d.ts" />

/*    movie.server.model.ts - definition of movie schema */

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var foo = 'test';

The error is thrown on line 6.

The .d.ts file references were placed in the appropriate folders and added to typings/tsd.d.ts by the commands:

tsd install node --save
tsd install require --save

The produced .js file seems to work fine, so I could ignore the error. But I want to know why this error occurs and what I am doing wrong.

May 31, 2022 in TypeSript by Logan
• 2,140 points
13,891 views

1 answer to this question.

0 votes

Here's a really easy work around:

declare var require: any
answered May 31, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
1 answer

TypeScript Object assign gives me an error property assign does not exist on type ObjectConstructor

For TypeScript 2.1 and higher, you can ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
2,064 views
0 votes
1 answer

What is "not assignable to parameter of type never" error in TypeScript?

All you have to do is define ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
57,185 views
0 votes
1 answer
0 votes
1 answer

Where to find TypeScript version in Visual Studio?

If you only have TypeScript installed for ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
2,481 views
0 votes
1 answer

Cannot access web3 object with typescript and ethereum

You still need to instantiate it first. ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,370 points
2,883 views
0 votes
1 answer

How to apply zoom animation for each element of a list in angular?

Hey @Sid, do check if this link ...READ MORE

answered Jul 30, 2019 in Others by Vardhan
• 13,150 points
1,548 views
0 votes
1 answer
0 votes
1 answer

Can't bind to 'formGroup' since it isn't a known property of 'form'

In order to rectify this error, you ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,680 points
21,273 views
0 votes
1 answer

Typescript: Can't find names - Error: cannot find name

A known issue: https://github.com/angular/angular/issues/4902 Core reason: the .d.ts file implicitly included ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
11,484 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP