为什么require("perf_hooks")失败? [英] Why require("perf_hooks") fails?

查看:241
本文介绍了为什么require("perf_hooks")失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,"perf_hooks"是Node.js的一部分.但是,当使用 npm test 进行测试时,它在以下情况下对我失败(某些文件名已更改):

In my understanding "perf_hooks" is a part of Node.js. However when testing with npm test it fails for me with the following (some filenames are changed):

Error: ENOENT: no such file or directory, open 'perf_hooks'
      at Object.openSync (fs.js:465:3)
      at Object.readFileSync (fs.js:368:35)
      at SandboxedModule._getCompileInfo (node_modules/sandboxed-module/lib/sandboxed_module.js:265:20)
      at SandboxedModule._compile (node_modules/sandboxed-module/lib/sandboxed_module.js:245:22)
      at createInnerSandboxedModule (node_modules/sandboxed-module/lib/sandboxed_module.js:183:23)
      at SandboxedModule.RecursiveRequireProxy (node_modules/sandboxed-module/lib/sandboxed_module.js:214:27)
      at /Users/asmirnov/Documents/blabla2.js:51:12
      at Object.<anonymous> (lib/profiler.js:53:3)
      at SandboxedModule._compile (node_modules/sandboxed-module/lib/sandboxed_module.js:251:19)
      at createInnerSandboxedModule (node_modules/sandboxed-module/lib/sandboxed_module.js:183:23)
      at SandboxedModule.RecursiveRequireProxy (node_modules/sandboxed-module/lib/sandboxed_module.js:214:27)
      at Object.<anonymous> (lib/blabla1.js:29:20)
      at SandboxedModule._compile (node_modules/sandboxed-module/lib/sandboxed_module.js:251:19)
      at createInnerSandboxedModule (node_modules/sandboxed-module/lib/sandboxed_module.js:183:23)
      at SandboxedModule.RecursiveRequireProxy (node_modules/sandboxed-module/lib/sandboxed_module.js:214:27)
      at SandboxedModule.requireInterceptor (node_modules/sandboxed-module/lib/sandboxed_module.js:227:9)
      at Context.<anonymous> (test/blabla1.js:73:22)
      at processImmediate (internal/timers.js:458:21)

这是使用它的文件( lib/profiler.js )的一部分:

This is a part of the file (lib/profiler.js) that uses it:

const {performance, PerformanceObserver} = (function()
{
  try
  {
    if (window && typeof window.performance == "undefined")
      throw new TypeError();
    return window;
  }
  catch (e)
  {
    return require("perf_hooks");
  }
})();

可能是什么原因?但是,在某些情况下( npm run .. ),它可以按预期工作.任何建议表示赞赏.

What can be a reason? However in some scenarios (npm run ..) it works as expected. Any suggestions are appreciated.

PS.节点相对较新:

PS. Node is relatively fresh:

> node --version
v14.8.0

推荐答案

这是沙盒模块";2.0.3已在2.0.4中修复.

That's a "sandboxed-module" 2.0.3 issue that was fixed in 2.0.4.

这篇关于为什么require("perf_hooks")失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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