我正在尝试将日期/时间记录到javascript控制台中。我收到的错误消息如下,是由下面的代码生成的。
ETA:该代码确实有效。日期将转到控制台。只是错误消息仍然存在
消息:
src / app / kdc / services / customers.api.service.ts(60,9)中的ERROR:错误 TS2591:找不到名称“ require”。您需要安装类型吗 节点的定义?尝试
npm i @types/node
,然后将node
添加到 tsconfig中的“类型”字段。
注意:我已经对tsconfig.json
文件进行了更改,并且还完成了npm i @types/node
和npm i @types/node --save
在运行npm
时的结果是3 high-security vulnerabilities
(请参见下文) )
这时我该怎么办?`
customer.api.service.ts
getCustomers(): Observable<Customers[]> {
return this.httpclient.get<Customers[]>(this._url)
.pipe( catchError(this.handleError));
}
handleError(error:HttpErrorResponse){
let rval = Math.random().toString(36).substring(7).toUpperCase();
require('log-timestamp');
console.error('MSG NO :' + rval );
console.error(error);
return throwError(rval + " <-> " + error.name + " <-> " + error.statusText );
}
ETA
我在这里Cannot find name 'require' after upgrading to Angular4找到了邮件,并更改了我的邮件
tsconfig.app.json
个文件-可能有些过分,但效果不错...
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [ "node" ],
"typeRoots": [ "../node_modules/@types" ]
},
答案 0 :(得分:5)
确保将类型放在tsconfig.app.json中,而不是tsconfig.json中
"compilerOptions": {
"module": "esNext",
"types": ["node"]
},
还要确保组件中的系统税看起来像这样
const someLib = require("someLib"); // make sure the name is match with your package name
然后停止角度cli,然后再次运行