module-from-string
module-from-string copied to clipboard
fix: global object conflicting property descriptors
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
@exuanbo is this project still active?