FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
175 stars 55 forks source link

Constants polyfill mixes named and default exports, breaks graceful-fs #25

Open IanVS opened 3 years ago

IanVS commented 3 years ago

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'?