最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error Cannot find module 'perf_hooks' when creating site with React-static - Stack Overflow

programmeradmin0浏览0评论

I got the following error when creating a site with react-static create mand:

Error: Cannot find module 'perf_hooks'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-static/lib/utils/index.js:45:19)

Just installed react-static using npm.

I got the following error when creating a site with react-static create mand:

Error: Cannot find module 'perf_hooks'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-static/lib/utils/index.js:45:19)

Just installed react-static using npm.

Share Improve this question asked Mar 2, 2019 at 12:26 MiguelSlvMiguelSlv 15.2k19 gold badges111 silver badges186 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

perf_hooks is available since nodejs v8.5.

Check your nodejs version by node -v.

My code had:

if (typeof performance === 'undefined') {
  // Older Node.js
  globals.performance = require('perf_hooks').performance;
} else {
  // Browser.
  globals.performance = performance;
}

to work around: https://github./nodejs/node/issues/28635 that hadn't been solved.

Since in that case the browser is taken care of trivially by the exposed global, I just hacked it to:

  globals.performance = eval('require')('perf_hooks').performance;

which makes webpack incapable of seeing the dependency as desired, as mentioned at: How can I make webpack skip a require

Tested on react-scripts 4.0.3.

发布评论

评论列表(0)

  1. 暂无评论