我正在尝试将日期/时间记录到 JavaScript 控制台中。我收到的错误消息如下,由下面的代码生成。
预计到达时间:该代码确实有效。日期将发送到控制台。只是错误消息仍然存在
消息:
ERROR in src/app/kdc/services/customers.api.service.ts(60,9): error TS2591: Cannot find name 'require'. Do you need to install type definitions for node? Try
npm i @types/node
and then addnode
to the types field in your tsconfig.
注意:我已经对 tsconfig.json
文件进行了更改,并且还完成了 npm i @types/node
和 npm i @types/node --save
运行npm
时,结果是3个高安全漏洞
(见下文)
此时我能做什么?`
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 );
}
预计到达时间
我在这里找到了这条消息Cannot find name 'require' after upgrading to Angular4并对我的进行了更改
tsconfig.app.json
文件 - 它可能有点矫枉过正,但它有效......
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [ "node" ],
"typeRoots": [ "../node_modules/@types" ]
},
最佳答案
确保将类型放入 tsconfig.app.json 而不是 tsconfig.json
"compilerOptions": {
"module": "esNext",
"types": ["node"]
},
还要确保组件中的系统税如下所示
const someLib = require("someLib"); // make sure the name is match with your package name
然后停止 Angular cli 然后再次运行
关于javascript - 有 Angular Material (8) S2591 : Cannot find name 'require' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60237785/