rollup-plugin-polyfill-node icon indicating copy to clipboard operation
rollup-plugin-polyfill-node copied to clipboard

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

Open IanVS opened this issue 4 years ago • 0 comments

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

IanVS avatar Jun 01 '21 16:06 IanVS