I got the following error when creating a site with react-static create command:
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.
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.com/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With