Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find name 'require' templateUrl

Tags:

angular

While loading the page, getting error as cannot find require, in the line where I used templateUrl, but the system is very much stable, don't know where is exactly the error is occuring..

import {Component, OnInit} from '@angular/core';
import {Http} from '@angular/http';
import {Title}     from '@angular/platform-browser';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html'
})

export class LoginComponent implements OnInit {

}
like image 876
NARGIS PARWEEN Avatar asked Jul 19 '26 00:07

NARGIS PARWEEN


1 Answers

You're using Typescript, the Typescript Compiler type-checks everything you compile for you to see if it can help pop out some errors for you. The error you're getting is Typescript letting you know it doesn't recognize the require function. The application runs fine because it is still eventually available at runtime and thus the error you're getting is merely a "warning" from the Typescript Compiler.

To fix this you'll have to "teach" Typescript about functions such as require, you can do that by installing nodejs types by running:

npm install --save @types/node

(You'd optionally need to add the following to your tsconfig.json so it loads types from node_modules/@types:

"typeRoots": [ "./node_modules/@types" ],)

like image 182
Amit Avatar answered Jul 20 '26 20:07

Amit