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
17,089 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,766 views