Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update limits and remove sections about bug #15

Open
alexander-akait opened this issue Oct 7, 2020 · 4 comments
Open

update limits and remove sections about bug #15

alexander-akait opened this issue Oct 7, 2020 · 4 comments

Comments

@alexander-akait
Copy link

https://github.com/ai/dual-publish#limits

We recommend to avoid default export because of bug in webpack.

It can be misleading because it is not a bug. Explanation - webpack/webpack#7973 (comment) Many other tools (for example babel) work similarly. Even rollup has https://rollupjs.org/guide/en/#outputinterop to control this, because this is a very controversial issue

@ai
Copy link
Owner

ai commented Oct 7, 2020

Why Node.js behaviour with CJS to ESM converting for default exports (of module has only default export, export it as object without wrappers) do not work for webpack?

It leads to inconsistency between Webpack and Node.js behaviour and it is the source of the problem.

@alexander-akait
Copy link
Author

alexander-akait commented Oct 7, 2020

Using node:

test.mjs

import cjs from './foo.cjs';
import mjs from './foo.mjs';

console.log(cjs);
console.log(mjs);

foo.cjs

// For:
// module.exports = { default: 'cjs' };
//
// output node and webpack is same:
//
// { default: 'cjs' }
module.exports = 'cjs';

foo.mjs

export default 'mjs';

Output:

cjs
mjs

Using webpack

Output:

cjs
mjs

@alexander-akait
Copy link
Author

CommonJS doesn't have default export

@ai
Copy link
Owner

ai commented Oct 7, 2020

Nope, I am talking about different problem.

You have dual CJS/ESM package:

// lib/index.mjs
export default 'lib'
// lib/index.cjs
module.exports = 'lib'

For Node.js both constructions will work:

require('lib') //=> 'lib'
import lib from 'lib' //=> 'lib'

In Webpack you will have a different result:

require('lib') //=> { default: 'lib' }

It is a open issue and seems like it was fixed in webpack 5, so it is a bug for my understanding of this term. But we can replace this line with recommendations using webpack 5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants