unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic
MIT License
358 stars 19 forks source link

Auto-mocking proxy not compatible with Conversion to primitive value #86

Closed chrisspiegl closed 1 year ago

chrisspiegl commented 1 year ago

Describe the feature

I am trying to use unenv to get something to work with the use of rollup and in another project with nuxt.js

I found that the auto mocking proxy runs into issues when the requesting library tries to convert something to a primitive value as in this example:

file:///Users/.../_worker.js:107963
    [http2$1.constants.HTTP2_HEADER_STATUS]: http2$1.constants.HTTP_STATUS_OK,
                       ^

TypeError: Cannot convert object to primitive value

I had the same issue with a library doing something like this:

const sys = os.platform()
if (sys && sys.length > 3) {}

In this case the auto mocking failed because the sys.length can't be provided as a primitive value.

Not sure this can be somehow enhanced but I thought I'd share my findings here.

Additional information

pi0 commented 1 year ago

Hi. This is because node:https is not implemented. Moving issue to #92