-
Notifications
You must be signed in to change notification settings - Fork 12
package.json "module": "./stable.esm.js" breaks stuff #9
Comments
proposed solution: revert the module change (or all changes), and republish it as "1.x".. or any other "breaking" version number. then includes like "stable": "^0.1.6" will not update to the newer one, but newer libraries can do so if they want to. |
Thanks for reporting this, sorry it came up! I'm not sure what the correct solution here is, though. // This export in our ES6 module:
function stable () { /* ... */ }
export default stable
// Looks like this to the webpack commonjs world, such as `accept-language`:
module.exports = { default: stable }
// Hence the 'stable is not a function' error Even if we publish the ES6 module changes as (breaking) semver 0.2, it'll just break again when So, I'm trying to figure out what to do here. Maybe @MattiasBuelens has an idea? |
I just noticed,
Could you try temporarily removing that line @simllll, just to see if the build works that way? |
Where can I find your webpack config? Or could you provide a small reproduction case? Or maybe the relevant part of your webpack config so I can try and reproduce the issue? |
Okay, I managed to reproduce this with a minimal Webpack project that uses
Other bundlers insert interopability helpers for handling ESM modules that were transpiled to CommonJS. For example, Babel does this: function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _foo = require("foo");
var _foo2 = _interopRequireDefault(_foo); and Rollup does this: foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; However, Webpack doesn't seem to do this (webpack/webpack#4742). I'll check if there's anything a library can do to make this work without needing interopability helpers. |
The best I could come up with is this comment:
So it looks like a library simply cannot use the |
Thanks guys for looking into this. I also stumpled across the comment @MattiasBuelens just posted. "Solution" number two seems very legit to me though. Regards |
I found another silly workaround, which is to add a
By default, Webpack prefers the browser entry point over module or main entry points. In this case, it would select the UMD bundle instead of the ES bundle, which "fixes" the issue. Still, not recommended. 😛 Anyway, for v0.1.x, I think we should just remove For a future v0.2.x release, we could consider a new public API that supports CJS and ESM. For example, rather than adding
This would mean that the CJS exports also change:
However, I'm not sure how bundlers handle mixing
and CJS:
Side node: it seems like Node will use |
Any plans? Right now I'm kinda stuck with this. |
Any success with this issue? I just came across the same problem using the https://github.com/ipld/js-ipld-dag-pb library as a dependency for the js Using Angular ^5.2.0
When using it like this:
Any ideas? |
For my own project, implemented in TypeScript, the change to the typings in stable 0.1.17 is a breaking change. My project imports it like this: import * as sort from 'stable';
Changing it to a default import fixes it: import sort from 'stable'; I think it would be best to incorporate Mattias's PR at least until 0.2+. |
I worked around it by forcing the
|
Sorry for the delay. I merged the PR and published 0.1.8. Still think this situation is weird, though. But I suppose we'll have to look into doing another release with one of the solutions mentioned by Mattias. |
@stephank Maybe also deprecate the 0.1.7 release with |
Done! |
I'm using accept-language node module which includes stable like this:
var stable = require("stable");
My whole project is bundled and packaged with webpack 4.5, and since this new release it includes require like this:
var stable = webpack_require(/*! stable */ "./node_modules/stable/stable.esm.js");
but unfortanutenaly this leads to "stable is not a function" errors.I guess the problem is that it should actually be a "import stable from.." statemetn instead of the regular requrie to let this work correctly. Or rewrite the stable call to stable.default(args...). I guess there are more situations like this though, and removing the "module" line in package.json fixes everything.
Not quite sure what is the correct approach to handle this. All I know: it doesn't work right now, and stable is the only package in my repro right now that has this kind of issue?
The text was updated successfully, but these errors were encountered: