unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic
MIT License
340 stars 18 forks source link

Missing `performance.now()` implementation #274

Closed farnabaz closed 2 weeks ago

farnabaz commented 2 weeks ago

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

pi0 commented 2 weeks ago

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.

farnabaz commented 2 weeks ago

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?

pi0 commented 2 weeks ago

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.

farnabaz commented 2 weeks ago
Screenshot 2024-06-19 at 14 09 32

Seems that these files are moved inside http/internal/ directory.

pi0 commented 2 weeks ago

Ah this is from h3... https://github.com/unjs/h3/pull/781 should fix in h3/nuxt nightly channel. Please let me know if other conflicts happening.