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

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

Closed
Routhinator opened this issue Aug 27, 2015 · 15 comments
Closed

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

Routhinator opened this issue Aug 27, 2015 · 15 comments

Comments

@Routhinator
Copy link

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

@mgonto
Copy link
Owner

mgonto commented Aug 27, 2015

Hey,

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

It's an alias, see alias section.

Cheers!

@mgonto mgonto closed this as completed Aug 27, 2015
@Routhinator
Copy link
Author

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
Copy link
Author

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

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

@jaydiablo
Copy link

@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: lodash/lodash#1407 (comment)

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?

@Vixxd
Copy link

Vixxd commented Jan 13, 2016

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

@jaydiablo
Copy link

@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

@preston
Copy link

preston commented Jan 14, 2016

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

@bourgeois247
Copy link

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.

@ferencdev
Copy link

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

_.contains = _.includes;

Thanks @bourgeois247

PascalHelbig added a commit to PascalHelbig/hwr-chat-frontend that referenced this issue Jan 28, 2016
Restangular hat lodash als Dependency. Durch eine neue Version funktioniert Restangular nicht mehr. Deshalb zwingen wir nun Restangular die Version 2.4 von lodash zubenutzen. (siehe mgonto/restangular#1225 )
@zanettin
Copy link

zanettin commented Feb 4, 2016

@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!

@ackimwilliams
Copy link

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

@preston
Copy link

preston commented Feb 9, 2016

@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.. 😄

@mgonto
Copy link
Owner

mgonto commented Feb 10, 2016

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

@preston
Copy link

preston commented Feb 10, 2016

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

@YassineFadhlaoui
Copy link

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

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

10 participants