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
18,293 views

1 answer to this question.