3

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 {

}
NARGIS PARWEEN
  • 1,489
  • 3
  • 16
  • 26
  • I am getting the same thing. Just started using the Angular CLI on a new project, and when I do `ng serve` I get the same error `Cannot find name 'require'` for all the components template urls and style urls... – EricC Nov 02 '16 at 07:38
  • The app works, though, it's just the annoying error message when building and in the console log... – EricC Nov 02 '16 at 07:44

1 Answers1

3

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" ],)

Amit
  • 4,274
  • 21
  • 25