module-from-string icon indicating copy to clipboard operation
module-from-string copied to clipboard

fix: global object conflicting property descriptors

Open mdevils opened this issue 11 months ago • 1 comments
trafficstars

In the modern versions of node.js many globals are defined as properties with accessors, providing them using globals parameter just throws an exception.

Here is an example reproduction code:

const importedFromString = await importFromString('export const result = typeof Buffer;', {
    globals: { Buffer },
});

Here is the error I'm getting:

TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>

The problem is that createGlobalObject() function extracts property descriptors from the current global and adds value to it and then adds that property descriptor to the generated global. Problem with it is that value cannot co-exist with get / set method as described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#set

mdevils avatar Dec 02 '24 20:12 mdevils

@exuanbo is this project still active?

mdevils avatar Jan 20 '25 12:01 mdevils