JakeChampion/polyfill-library

Unhandled Rejection (TypeError): fs$readdir is not a function

param-kothari opened this issue · 2 comments

This is a bug report, or rather, we needed some help to resolve this issue regarding the usage of polyfill-library.

What

We faced an issue while installing and using the polyfill library. Upon installing, we tried to use the library with the following code, taking inspiration from this comment -> Link

const polyfillLibrary = require('polyfill-library');

const polyfillBundle = polyfillLibrary.getPolyfillString({
	minify: true,
	unknown:'polyfill'
	features: {
		'all': { flags: ['gated'] }
	}
}).then(function(bundleString) {
	fs.writeFileSync('polyfill-all.js', bundleString, 'utf-8');
});

However, we are facing two errors for this: Unhandled Rejection (TypeError): fs$readdir is not a function and Unhandled Rejection (TypeError): fs$readFile is not a function. Upon digging deeper, we found that this could be an issue with graceful-fs where the imported fs module doesn't contain the readdir and readFile methods.

Also, in the package.json file for graceful-fs, the files list include fs.js whereas it's not present in the dir. So, we think that there could be an issue related to that.

Details

  • The expected behaviour is that the polyfills should be generated, but instead, we are getting the two errors mentioned above.
  • This is occurring for us directly upon normal installation and usage of the library as described in the docs.
  • Environment: Chrome 101.0.4951.64, macOS (laptop)
  • nvm version used for installation: v14.17.5

Screen Shot 2022-05-26 at 1 12 01 AM

Screen Shot 2022-05-26 at 1 12 20 AM

Not sure if this issue is related to the following one, but I'm attaching a link just in case -> #479

Polyfill-library does not work in a browser context which is why this issues happens

Thanks, got the issue