flow icon indicating copy to clipboard operation
flow copied to clipboard

Can't import {Buffer} from 'buffer', same with EventEmitter/events

Open josephsavona opened this issue 8 years ago • 2 comments

Flow (tested with 43 and 42) rejects the following line, claiming that buffer does not have an export named Buffer:

import {Buffer} from 'buffer';

It allows import Buffer from 'buffer', except that this doesn't work: 'buffer' doesn't export a default value, so that throws when compiling ES6 imports to require statements e.g. with Babel.

The same is true for import {EventEmitter} from 'events', which works but is rejected by Flow.

The use case I'm trying to solve is explicitly Buffer/EventEmitter so that I can produce node builds (using the actual node modules) and browser builds (rewriting those imports to 'buffer/' and 'events/') that require browser polyfills for them.

josephsavona avatar Apr 13 '17 16:04 josephsavona

this is still not fixed?

despite the PR that was supposed to support Buffer, I'm having it uncovered:

capture d ecran 2018-10-20 a 10 31 11

tried both require() and import syntaxes

gre avatar Oct 20 '18 08:10 gre

@gre this was fixed to a degree. There's no flow error anymore because Buffer is defined in buffer but it's just not typed properly so it defaults to any.

I think in general this issue is resolved. Though looking at the definition, I don't know why it was defined as Buffer: typeof global.Buffer instead of Buffer: Buffer which may make it more useful

Brianzchen avatar Aug 31 '20 22:08 Brianzchen