standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Deprecation warning triggered on parsing morgan #812

Open rchl opened 5 years ago

rchl commented 5 years ago

Importing morgan package triggers deprecation warning due to accessing the default property of morgan import.

That property is marked as deprecated in morgan with this code:

var deprecate = require('depd')('morgan')
// ...
deprecate.property(morgan, 'default', 'default format: use combined format')

It seems that esm triggers deprecation warning on parsing.

Works without warning in 3.2.20. Version 3.2.21 is the first one that gives the warning.

Repro sandbox: https://codesandbox.io/s/esmpropertyaccessbug-8djiv

borisding commented 5 years ago

I believe it's related to this reported issue:

https://github.com/expressjs/morgan/issues/190

rchl commented 5 years ago

It does indeed look the same. The question is only whether this is bug in esm or morgan...

It's true that morgan has default property on exported object but is that something that can be distinguished from actual default exports?

mbrowne commented 5 years ago

I think this may very well be a bug in esm...it's problematic for morgan to address this because the legacy API depends on exports.default pointing to morgan's default format function (which returns a string) rather than the morgan function itself. The warning doesn't happen when using node's experimental-modules flag so it seems like it should be possible for it to work without a warning in esm also, although that's just an educated guess.

Because the code for morgan does not contain the __esModule flag, it seems like esm should be able to realize that exports.default is not the default export of an ES6 module, but rather just a regular export of a CommonJS module that happens to be named default. I took a quick look at the source code in this repo and I see that it is checking for __esModule in a couple places, but maybe there's some additional place that check needs to be added...