unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing `performance.now()` implementation

farnabaz opened this issue · comments

Environment

------------------------------
- Operating System: Darwin
- Node Version:     v20.12.2
- Nuxt Version:     3.12.3-28645501.2b6967fb
- CLI Version:      3.11.2-1718100309.03d4a54
- Nitro Version:    2.10.0-28644031.f6f23270
- Package Manager:  pnpm@9.3.0
- Builder:          -
- User Config:      devtools
- Runtime Modules:  -
- Build Modules:    -

Reproduction

Repo: https://github.com/farnabaz/unenv-performance-now
Demo: https://nuxt-ot.nuxt.dev

Describe the bug

Some packages like @opentelemetry/core imports performance directly from perf_hooks and thus this import handles by unenv in non-node environments. The issue is that performance polyfill is not yet implemented (or at least performance.now is not implemented) and calling performance.now() return proxy function.

As the result, we get this error
Screenshot 2024-06-19 at 13 06 12

Additional context

No response

Logs

No response

Thanks for nice reproduction.

We have implemented performance now and it is available in nightly channel and will be fore unenv v2 / nitro v3 / nuxt v4.

In the meantime i would suggest to manually add a polyfill to the apps.

Unfortunately, I can't use unenv-nightly because of structure change in dist directory regarding the internals.

In the meantime i would suggest to manually add a polyfill to the apps.

How can I add polyfill manually to mock the perf_hooks imports?

structure change in dist directory regarding the internals.

Which files are breaking your project? If minor, we might add it for backward compatibility so you can leverage v2.

How can I add polyfill manually to mock the perf_hooks imports?

Configure unenv: { polyfills: {}} in nuxt/nito config and add something like this.

Screenshot 2024-06-19 at 14 09 32 Seems that these files are moved inside `http/internal/` directory.

Ah this is from h3... unjs/h3#781 should fix in h3/nuxt nightly channel. Please let me know if other conflicts happening.