rollup/rollup-plugin-node-resolve

Why check for `default` on commonjs modules?

maranomynet opened this issue · 2 comments

I'm curious:
Since CommonJS module's don't have the concept of an explicit "default" export...

Why does this:

import foo from './_js/commonjs-module.js';
alert(foo.answer);

...result in this?

var module$1 = __commonjs(function (module) {
module.exports = {
  msg: 'This is a CommonJs module',
  answer: 42,
};
});
var foo = (module$1 && typeof module$1 === 'object' && 'default' in module$1 ? module$1['default'] : module$1);
alert(foo.answer);

I mean, why not simply say var foo = module$1; since this seems to be the inevitable end result every time anyway?

I'm curious too, webpack depends on obj.__esModule, check use
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

rollup depends on 'default' in a check use
(a && typeof a === 'object' && 'default' in a ? a['default'] : a)

I'm sorry, this is the wrong repository. Should have been the commonjs plugin