找不到名称"require" templateUrl [英] Cannot find name 'require' templateUrl

查看:169
本文介绍了找不到名称"require" templateUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在加载页面时,在我使用templateUrl的那一行中出现了找不到错误所需的错误,但是系统非常稳定,不知道错误的确切位置.

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 {

}

推荐答案

您正在使用Typescript,Typescript编译器会为您编译的所有内容进行类型检查,以查看它是否可以帮助您弹出一些错误. 您收到的错误是Typescript,让您知道它无法识别require函数. 该应用程序运行良好,因为它最终仍可以在运行时使用,因此,您收到的错误只是来自Typescript编译器的警告".

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.

要解决此问题,您必须教"打字稿有关诸如require之类的功能的信息, 您可以通过运行以下命令安装nodejs类型来做到这一点:

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

((您可以选择将以下内容添加到tsconfig.json中,以便它从node_modules/@types中加载类型:

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

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

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

这篇关于找不到名称"require" templateUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆