Failed to execute 'measure' on 'Performance': 'NotFound' cannot have a negative time stamp.
Link to the code that reproduces this issue
https://github.com/MOSAIC-ETC/website
To Reproduce
- Start the application in development mode (next dev)
- Go to a non-existing page (/404, for example)
- Make a change in the code of
[locale]/not-found.tsx(change the text) - Update the page some times
- If it doesn't work, go back to step two, after some time (not very long, but it is somewhat random), it should appear
Current vs. Expected behavior
The error shouldn't happen.
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Available memory (MB): 15893
Available CPU cores: 16
Binaries:
Node: 22.18.0
npm: 11.6.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.0.2-canary.16 // Latest available version is detected (16.0.2-canary.16).
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I'm using WSL.
The error has something to do with the CatchAllPage that shows the NotFound component. The error may show outside a not-found page, and it shows randomly (but frequently) during development when i'm making changes to the code. I didn't find anything related to cannot have a negative time stamp anywhere else.
Quick workaround: using a small patch that overrides performance.measure in dev and ignores the error. If you want to see the pre-patch behavior locally, check out commit 90d070d (before the patch).
Here is the code (not the best workaround, honestly):
(function () {
try {
var perf = window.performance;
if (!perf || typeof perf.measure !== "function" || perf.__patched) return;
var original = perf.measure.bind(perf);
perf.__originalMeasure = original;
perf.measure = function () {
try {
return original.apply(perf, arguments);
} catch (err) {
var msg = (err && err.message) || "";
var name = (err && err.name) || "";
if (
msg.indexOf("negative time stamp") !== -1 ||
name === "InvalidAccessError" ||
name === "SyntaxError"
) {
return;
}
throw err;
}
};
perf.__patched = true;
} catch (_) {
// ignore
}
})();
I have been getting "Failed to execute 'measure' on 'Performance': 'Page' cannot have a negative time stamp" lately while building a Saas. For me, it happened randomly.