Closed kipz closed 7 years ago
Thanks for the tip about ScriptObject
- that's the thing I was missing!! I took the liberty of making a broader fix in this PR: https://github.com/coveo/nashorn-commonjs-modules/pull/17
I copied the test you included here and it's now passing.
(btw I created a new PR because I know of no way to "extend" on yours, sorry if it's poor GH "etiquette").
Fixed by #17
The following code:
does not work in Nashorn, leading to an Exception:
This is because our
exports
object is a Nashorn Bindings object, and Nashorn only supports defining properties on pure JS objects (those that extend ScriptObject - an internal Nashorn class).We are experiencing this issue due to a change in the TypeScript compiler:
https://github.com/Microsoft/TypeScript/issues/14351
but it's not uncommon for other JS processing tools to do the same:
https://duckduckgo.com/?q=Object.defineProperty(exports%2C+%22__esModule%22%2C+%7B+value%3A+true+%7D)%3B&atb=v51-6_c&ia=web
and of course, it's totally valid JavaScript
Ultimately, we may want to consider doing this for all global vars, but this seemed like a much more invasive change to the design.