benjamn / benjamn/reify

Overriding Rollup/Babel-compiled `export *` causes error

Open
#236 1 comment 0 reactions 1 assignee Claimed by @benjamn View on GitHub
Dominant language
JavaScript
Stars
740
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Re-exporting all exports of a module that was compiled with Rollup or Babel and overriding one of the exports causes a `TypeError` because Reify attempts to set a read-only property in the `exports` object. Reproduction repository: https://github.com/klaussner/reify-issue-236.

Rollup input:
```js
export * from "fs";
```

Rollup output (Babel output is similar):

```js
// rollup-output.js

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });

var fs = require("fs");

Object.keys(fs).forEach(function(k) {
if (k !== "default")
Object.defineProperty(exports, k, {
enumerable: true,
get: function() {
return fs[k];
}
});
});
```

If the output is used like this with Reify, a `TypeError` is thrown:

```js
export * from "./rollup-output";
export const existsSync = ":)";
```

```
TypeError: Cannot set property existsSync of # which has only a getter
at Entry.Ep.runGetters (node_modules/reify/lib/runtime/entry.js:165:33)
at Entry.Ep.runSetters (node_modules/reify/lib/runtime/entry.js:211:8)
at Module.runSetters (node_modules/reify/lib/runtime/index.js:115:36)
at Object.extWrap (node_modules/reify/node/compile-hook.js:57:9)
at Object.extManager (node_modules/reify/node/compile-hook.js:19:12)
at Object.manager [as .js] (node_modules/reify/node/wrapper.js:108:20)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.