Lodash (_) being overwritten with undefined in 1.6?

#1

I’ve been using lodash as a global import in my project, like this:

_ = require('lodash')

It’s been working fine until now. But after I upgraded to 1.6 I’m getting a ton of cannot read property 'includes' of undefined etc. And if I check _ in the Meteor shell it’s undefined

On the client it works though, the problem is only on the server side

I also tried

lodash = require('lodash')
_ = lodash

In the Meteor shell, lodash works but _ is undefined.

TypeError: Cannot read property '_' of undefined
#2

Its a longshot, but you might want to use import/export since its standard in Meteor:

import _ from 'lodash';

I never had any issues using it like this I’m using it like this since Meteor 1.3.

#3

I’m sure a local import works. But I’d like to be able to have Lodash, which I use everywhere, available globally, like I used to.

I also tried this btw, with the same problem:

import lodash from 'lodash'
_ = lodash

So it’s not require that’s the issue, but for some reason the global _ variable doesn’t work anymore.

#4

use everywhere, available globally

have you try this?

import lodash from 'lodash'
window._ = lodash
#5

window doesn’t work on the server, but I tried:

import lodash from 'lodash'
global._ = lodash

Same result.

#6

Hmm, I removed all the version constraints from my Meteor packages and ran meteor update, and now it works again.

#7

haha same problem here! :wink:
What do you mean exactly @herteby?
Remove all the @-version- Strings in the .meteor/packages file and then just run meteor update?
That’s it? Gotta try that.

#8

Yup exactly. Not 100% sure that’s really what solved it, but now it works again anyway.

#9

I noticed this and reported it in early alpha 1.6. It seemed to happen to me only when the Meteor shell was opened. It seems like Meteor shell overwrites the _ global variable on the server as well.

2 Likes
#10

This info may help Migrating to Meteor 1.6

#11

@hexsprite Ah you are right! My solution was just a red herring. When I launched the shell again now, the problem returned.

@skirunman My issue is with globally importing lodash, not that I’ve been relying on Meteor’s Underscore.

#12

Removing all the @-version- Strings in the .meteor/packages file and then running meteor update also worked for me!

#13

Are you sure it’s not that you were running the shell before, and are not running it now?

#14

I am 90% sure that when I posted my own thread some days ago the error occured immediately before opening the shell. Only afterwards I opened the shell and began to debug - I usually work without any open meteor shell.

After the first error I first tried to console.log(_) in my imports/startup/server/index.js and only then opened the meteor shell. so yeah …

#15

Hmm :thinking: so maybe there are two different bugs that both cause _ to be undefined then.