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 badges2 Answers
Reset to default 2perf_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.