首页 > 解决方案 > nodejs 抛出 TypeError: process.uptime is not a function

问题描述

我是 nodejs 的新手,我正在使用 prom-client,在使用process.uptime(). 我尝试添加几个包但没有运气(前三个包是针对类似的其他错误):

"cluster": "^0.7.7",
    "dns": "^0.2.2",
    "repl": "^0.1.3",
    "node": "^12.2.0",
    "process": "^0.11.10"

这是我的其他包:

"@material-ui/core": "1.2.0",
    "@material-ui/icons": "1.1.0",
    "classnames": "^2.2.6",
    "cross-env": "^5.2.0",
    "jquery": "^3.4.1",
    "js-yaml": "^3.13.1",
    "npm": "^6.9.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-loader-spinner": "^2.3.0",
    "react-number-format": "v3.0.0",
    "react-scripts": "1.1.4",
    "express": "4.15.3",
    "prom-client": "^11.3.0"

我是否缺少一些可以提供所有这些功能的基本库?我可以在https://nodejs.org/api/process.html#process_process_uptime看到这个方法

我在浏览器上收到错误消息,但不在日志中:

TypeError: process.uptime is not a function
(anonymous function)
node_modules/prom-client/lib/metrics/processStartTime.js:4
  1 | 'use strict';
  2 | 
  3 | const Gauge = require('../gauge');
> 4 | const nowInSeconds = Math.round(Date.now() / 1000 - process.uptime());
  5 | 
  6 | const PROCESS_START_TIME = 'process_start_time_seconds';
  7 | 
View compiled
./node_modules/prom-client/lib/metrics/processStartTime.js

标签: node.jsnpm

解决方案


似乎您正在创建一个react.js应用程序,而不是一个node.js服务器应用程序。

当node.js是服务器端时, react是前端。

没有process.uptime(),因为没有涉及node.js服务器。

prometheus.io库不提供react客户端。


推荐阅读