Underscore: Altered export format/API in semver minor breaks community packages

Created on 30 Mar 2020  ·  8Comments  ·  Source: jashkenas/underscore

I encountered some very weird bugs today in a third-party package (natural) with errors like TypeError: Cannot read property 'without' of undefined. This turns out to be because it imports underscore like this:

var Tokenizer = require('./tokenizer'),
    util = require("util"),
    _ = require('underscore')._;

It appears that the latest version exports the whole shebang as a default export, not as a named value on the exports. That’s probably fine…except for any packages that do the above.

Perhaps _ should still be exposed as an alias for the default export? Changing something so major as the top-level API seems like a major breaking change (not a _minor_ semver change!), and after all underscore is used as a dependency by a lot of packages out there.

All 8 comments

Same issue here.. seems like _ is being exported as undefined: https://github.com/jashkenas/underscore/issues/2835

Pinging @jgonggrijp — it looks like we'll need a 1.10.2 patch follow-up.

Specifically, I think that it was the removal of the old shim code for the previous Node API that caused the problem, here: https://github.com/jashkenas/underscore/compare/1.9.2...1.10.0#diff-0f36b362a0b81d6f4d4bfd8a7413c75dL45-L60

... @jgonggrijp — do you think there would be a problem with adding something like that back in?

This is definitely an oversight, sorry about that.

@jashkenas your link doesn't seem to work so I can't see what you mean. Perhaps something like this in the index-default?

var _ = mixin(allExports);
_._ = _;
export default _;
var _ = mixin(allExports);
_._ = _;
export default _;

This is exactly what I was doing! Super.

This should be fixed now in 1.10.2, which I've pushed up to NPM. Please give that a try, and let me know if everything is back to normal. Apologies for the screwup.

@jashkenas u r GOD! :angel: Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

acl0056 picture acl0056  ·  5Comments

arieljake picture arieljake  ·  4Comments

clouddueling picture clouddueling  ·  3Comments

arypbatista picture arypbatista  ·  3Comments

jdalton picture jdalton  ·  4Comments