FredKSchott / FredKSchott/rollup-plugin-polyfill-node
Constants polyfill mixes named and default exports, breaks graceful-fs
- Dominant language
- TypeScript
- Stars
- 193
- Forks
- 60
- PR merge metrics
- No merged PRs in 30d
Description
I've found that when named and default exports are mixed, the helper function `getDefaultExportFromNamespaceIfNotNamed` doesn't work correctly, it's defined as:
```
function getDefaultExportFromNamespaceIfNotNamed (n) {
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
}
```
Which means that code being compiled would need to import the `default` key specifically. This is mentioned here as well: https://rollupjs.org/guide/en/#outputexports.
The spot I'm seeing this cause problems is with `graceful-fs`. It has an `var constants = require('constants');`, and then later on it does a check for `constants.hasOwnProperty('O_SYMLINK')`, which blows up because it's treating the import as a `import * as constants`, which doesn't have `hasOwnProperty` and thus blows up.
I'm not sure what the right approach is, other than maybe only exporting a default object? Does node.js support `import {ENETDOWN} from 'constants'?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.