简体   繁体   English

Node.js-performance.now不是函数

[英]Node.js - performance.now is not a function

I have a Node.js app. 我有一个Node.js应用。 When I run node -v from the command-line, I see the following: 当我从命令行运行node -v ,我看到以下内容:

v10.3.0 V10.3.0

This is relevant because I'm interested in using the Performance Hooks . 这很重要,因为我对使用Performance Hooks感兴趣。 I've created the most basic thing I can think of, which looks like this in an in a file named 'index.js': 我创建了我能想到的最基本的东西,它看起来像在一个名为“ index.js”的文件中:

const performance = require('perf_hooks');

let p = performance.now();

When I run node index.js from the command-line, I get an error that says: 当我从命令行运行node index.js ,出现错误消息:

TypeError: performance.now is not a function TypeError:performance.now不是函数

Why am I getting this error? 为什么会出现此错误? What am I missing? 我想念什么?

The perf_hooks module exports several things, one of them is performance , so using object destructuring you could do: perf_hooks模块导出了几件事,其中之一是performance ,因此使用对象perf_hooks可以做到:

const { performance } = require('perf_hooks');

Or with object access: 或通过对象访问:

const performance = require('perf_hooks').performance;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM