restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Lodash no longer works as a dependency, Underscore is required.

Open Routhinator opened this issue 11 years ago • 15 comments

TypeError: _.contains is not a function

Lodash does not have a .contains() function. I've searched through the code. Underscore does, however Lodash, if it had one, has removed it. As of right now, installing Restangular today will only work with Underscore.js

Docs should be updated, unless you want to go the route of adding support for the new functions in lodash.js

Routhinator avatar Aug 27 '15 23:08 Routhinator

Hey,

It does exist: https://lodash.com/docs#includes

It's an alias, see alias section.

Cheers!

mgonto avatar Aug 27 '15 23:08 mgonto

TypeError: _.contains is not a function at Object.Configurer.init.config.isSafe (https://dev.amateurwriting.net/static/libraries/angular/restangular.js:21:16)

Restangular does not work with lodash. Check the error. Lodash is loaded and accessible, Restangular can see that, however restangular is unable to find the contains function. It's only working with Underscore.js.

Routhinator avatar Aug 27 '15 23:08 Routhinator

In the newest release of lodash, there is no contains:

https://raw.githubusercontent.com/lodash/lodash/master/lodash.js

Routhinator avatar Aug 27 '15 23:08 Routhinator

@Routhinator The last tagged version of lodash (3.10.1) does have the "contains" alias:

https://github.com/lodash/lodash/blob/3.10.1/lodash.js#L12065

master branch right now is 4.0.0-pre. The "contains" alias is still listed in the docs: https://github.com/lodash/lodash/tree/master/doc#collection but yes, the alias doesn't exist in lodash.js (or dist). It looks like they have removal of aliases on the roadmap: https://github.com/lodash/lodash/wiki/Roadmap

Some discussion about alias removal: https://github.com/lodash/lodash/pull/1407#issuecomment-134213932

I think with 4.0.0 lodash is drifting away from underscore compatibility, so it may be difficult for projects to support both, unless a compatibility library is put in-between. Possible to pin your lodash dependency to latest 3.x release?

jaydiablo avatar Nov 09 '15 18:11 jaydiablo

Literally just installed Restangular and on my very first 'get()' call I get: TypeError: _.contains is not a function

Lodash in my bower_components folder is listed as lodash v4.0.0 so I guess I will have to roll that back to an earlier version? However whenever I run 'bower update' now I'll have to exclude this somehow.

EDIT: Actually have another things that depend on lodash so this is not a preferred option

Vixxd avatar Jan 13 '16 22:01 Vixxd

@Vixxd you should be able to pin your lodash version to 3.x in your bower.json file like so:

"lodash": "~3.0",

bower update should obey that and won't install > 3.x

jaydiablo avatar Jan 13 '16 23:01 jaydiablo

I switched over to underscore just for Restangular. Not what I want to do, but avoids indefinitely pinning to an old lodash version. :-/

preston avatar Jan 14 '16 17:01 preston

as @mgonto [the creator of Restangular] said, it exists under the alias "_.includes" https://lodash.com/docs#includes.

So what I did was, immediately after including the Lodash library, I set _.contains = _.includes just before I included the Restangular library. If you are using Browserify for your bundling needs, you still need to set Lodash globally on the window object for Restangular to have access, after which you can set _.contains = _.includes.

Hope that helps someone save a minute or 2, cheers.

bourgeois247 avatar Jan 16 '16 09:01 bourgeois247

Yes i also solved it with a one liner in my (few but useful) global functions file.

_.contains = _.includes;

Thanks @bourgeois247

ferencdev avatar Jan 20 '16 16:01 ferencdev

@mgonto would be great, if you could add the online liner from @bourgeois247 to you scripts. just added it on dist/restangular.js on line 8 and everything looks great so far. thanks a lot for all your great work on this project!

zanettin avatar Feb 04 '16 16:02 zanettin

I second @zanettin's suggestion. Restangular is broken and unusable at this point. Time to fork :(

ackimwilliams avatar Feb 09 '16 03:02 ackimwilliams

@mgonto Just curious if you're still interested in maintaining Restangular? Sounds like you might have some volunteers on this thread if not! Awesome work man.. :smile:

preston avatar Feb 09 '16 15:02 preston

Hey @preston, unfortunately, I'm not mantaining this anymore, I'm actively looking for people that want to mantain this so whoever wants to do it, I'm 100% years :D

mgonto avatar Feb 10 '16 17:02 mgonto

I wouldn't be a good choice, but there are a ton of existing forks. @elnygren / @R-Kurbatovvakoms / @nfntynl any takers?

preston avatar Feb 10 '16 18:02 preston

you can solve this issue by adding this script after including lodash :

<script>
     _.contains = _.includes;
    </script>

or you can browse the restangular.js file and change _.contains by _.includes

YassineFadhlaoui avatar Mar 04 '16 12:03 YassineFadhlaoui