Esm: v3.0.61 some globals missing

Created on 2 Jul 2018  路  7Comments  路  Source: standard-things/esm

still converting tests to use esm and jest and noticed that some (other) globals are missing. 馃槙

scenario is the same as https://github.com/standard-things/esm/issues/487, and the same repro can be used: https://github.com/dnalborczyk/esm-jest-repro/tree/jest-no-global (with v3.0.61, fixes global)

I made a list based off: https://nodejs.org/api/globals.html. not sure if the list is conclusive , nor do I know if everything even should exist (e.g. __dirname, require, etc.):

| global object | status |
| ------------- | ------------- |
| Buffer | exists |
| __dirname | exists |
| __filename | exists |
| clearImmediate | exists |
| clearInterval | does not exist |
| clearTimeout | does not exist |
| console | exists |
| exports | exists |
| global | exists |
| module | exists |
| process | exists |
| require | exists |
| setImmediate | exists |
| setInterval | does not exist |
| setTimeout | does not exist |
| URL | does not exist |
| URLSearchParams | does not exist |

in addition:

| global object | status |
| ------------- | ------------- |
| util | does not exist (note: global.util does not exist as well) |

bug

Most helpful comment

@dnalborczyk

just curious, is this reproducible without jest and esm?

I have a few hunches. I suspect it has to do with an object uses as the context for multiple vm.Script instances.

Update:

v3.0.62 is released :tada:

All 7 comments

Hmm okay!

Before I was using the global jest provides us (not the real global). It looks like what they are providing is a little incomplete. I can mesh the two globals (using the real global to fill in the gaps of jest). Thanks for the detailed report btw. It's always super helpful to see something like that.

no problem! same goes back to you, thank you!!!

btw, I forgot to mention, I'm sure you know: URL and URLSearchParams only exist in node v10+

I also just noticed that util is a node.js global as well. I'll add it to the list above.

Patched https://github.com/standard-things/esm/commit/19efd9acef5d3e38de7239d6bd7e89db83842ba0 and https://github.com/standard-things/esm/commit/2bf85e9c385408ef017c0f911dfd02a1c327839b.

Update:

This was interesting and may be an engine bug. I noticed that the unsafeGlobal _(aka global)_ would have the URL and URLSearchParams properties on it but they weren't showing up as free vars. When I would get the keys on the global the keys for URL and URLSearchParams would be missing _(even when using Reflect.ownKeys and Object.getOwnPropertyNames)_.

However, global.hasOwnProperty("URL") and Reflect.getOwnPropertyDescriptor(global, "URL") would return positive results. So I found that one way to get them to show up was to delete them and re-add them exactly as they were _(that is why it looks like an engine bug)_.

that's indeed weird. do you mean by possible "engine bug" V8?

just curious, is this reproducible without jest and esm?

@dnalborczyk

just curious, is this reproducible without jest and esm?

I have a few hunches. I suspect it has to do with an object uses as the context for multiple vm.Script instances.

Update:

v3.0.62 is released :tada:

nice, thanks!! all tests are passing! :smiley:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clock157 picture clock157  路  3Comments

janusqa picture janusqa  路  3Comments

ericelliott picture ericelliott  路  3Comments

Pokute picture Pokute  路  3Comments

StphamZ picture StphamZ  路  3Comments