Skip to content

tryGetPerformanceHooks throws on Stackblitz with ts 5.5.3 #59296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JeanMeche opened this issue Jul 16, 2024 · 3 comments · Fixed by #59300
Closed

tryGetPerformanceHooks throws on Stackblitz with ts 5.5.3 #59296

JeanMeche opened this issue Jul 16, 2024 · 3 comments · Fixed by #59300

Comments

@JeanMeche
Copy link
Contributor

JeanMeche commented Jul 16, 2024

🔎 Search Terms

typescript
tryGetPerformanceHooks
stackblitz

🕗 Version & Regression Information

When running an Angular project on stackblitz (on the old runtime, not Webcontainers), typescript.js throws

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'timeOrigin')
    at tryGetPerformanceHooks (typescript.js:5266:27)

This happens on 5.5.3, but downgrading to 5.4 fixes the issue.

The typescript code probably isn't defensive enough depending on the runtime.

⏯ Playground Link

https://stackblitz.com/edit/angular-next-mqukjf?file=src%2Fmain.ts

💻 Code

No response

🙁 Actual behavior

Throws when running TS 5.5.3

🙂 Expected behavior

Should run fine as it did with TS 5.4

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

That doesn't seem to be an issue with TypeScript itself.

@JeanMeche
Copy link
Contributor Author

JeanMeche commented Jul 16, 2024

That's debatable, the root cause here is that isNodeLikeSystem() returns true on their web worker even though it's not a node environment.

require("perf_hooks") returns undefined.

if (isNodeLikeSystem()) {
try {
// By default, only write native events when generating a cpu profile or using the v8 profiler.
const { performance } = require("perf_hooks") as typeof import("perf_hooks");
return {
shouldWriteNativeEvents: false,
performance,
};
}

@jakebailey
Copy link
Member

I'll make the code more resilient, but it's a little unfortunate that StackBlitz has chosen to make the require not throw, but return an empty object or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants