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

Meteor shell breaks Underscore in 1.0.4.x #4010

Closed
artisonian opened this Issue Mar 24, 2015 · 11 comments

Comments

Projects
None yet
6 participants
@artisonian

artisonian commented Mar 24, 2015

Underscore mixins break in v1.0.4.x after opening the shell tool. See https://github.com/artisonian/meteor-shell-bug for details and reproduction steps.

@iameli

This comment has been minimized.

iameli commented Mar 25, 2015

Not underscore-specific -- I just reproduced with moment.

EDIT: @artisonian, I can repro with that library without even having to type _ into the console. Merely starting meteor shell is enough for me to get "Exception while invoking method 'ensure' TypeError: Cannot call method 'apply' of undefined"

@glasser

This comment has been minimized.

Member

glasser commented Mar 26, 2015

Ah, good catch. I missed this when reviewing 2443d83 which went into 1.0.4. meteor shell replaces whatever the global object's _ is with the _ read in shell-server.js's own var _ = require('underscore'). This means that if you mutate _ like you do in your example, meteor shell will replace it with the unmutated version. (It will also lose some minor changes we made to underscore around recognizing arrays.)

@glasser glasser closed this in da87051 Mar 26, 2015

@rclai

This comment has been minimized.

rclai commented Mar 27, 2015

Does it also fix the moment issue too?

@glasser

This comment has been minimized.

Member

glasser commented Mar 27, 2015

Well, I don't know what the moment issue is (no reproduction).

@artisonian

This comment has been minimized.

artisonian commented Mar 27, 2015

It's similar. moment sometimes gets deleted on the server after opening the shell tool. I actually noticed the problem with Underscore while trying to reproduce the issue with moment (I don't have a recipe for it yet). I'll try a local build to see if I can reproduce it reliably.

@c316

This comment has been minimized.

c316 commented Apr 1, 2015

I think I have a way to reproduce the issue.

meteor create test-moment
cd test-moment
meteor

after it starts stop it, then run
meteor add momentjs:moment
meteor
meteor shell
moment()
// this prints out
{ _isAMomentObject: true,
_isUTC: false,
_pf:
{ empty: false,
unusedTokens: [],
unusedInput: [],
overflow: -2,
charsLeftOver: 0,
nullInput: false,
invalidMonth: null,
invalidFormat: false,
userInvalidated: false,
iso: false },
_locale:
{ _ordinalParse: /\d{1,2}(th|st|nd|rd)/,
ordinal: [Function],
_abbr: 'en',
_ordinalParseLenient: /\d{1,2}(th|st|nd|rd)|\d{1,2}/ },
_d: Wed Apr 01 2015 14:43:27 GMT-0500 (CDT) }

Now run
meteor add meteorhacks:npm
You might have to restart meteor
In the packages.json file add this
{
"body-parser": "1.9.2",
}

Add this route to your route
Router.route('/webhook', function () {

// Receive an event, check that it contains a data.object object and send along to appropriate function
var request = this.request.body;
if(request.data && request.data.object){
    console.dir(request.data.object);
    var event = Events[request.type](request);
    this.response.statusCode = 200;
    this.response.end('Oh hai!\n');
} else {
    this.response.statusCode = 400;
    this.response.end('Oh hai!\n\n');
}

}, {where: 'server',
name: 'stripe_webhooks'
});

Create a folder "server" then a file server.js and type Events = {};
Now send a request via runscope or postman and you'll see an error like this one.

W20150401-15:47:01.276(-5)? (STDERR) ReferenceError: Events is not defined
W20150401-15:47:01.276(-5)? (STDERR) at [object Object].Router.route.where (app/both/router.js:7:21)
W20150401-15:47:01.276(-5)? (STDERR) at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
W20150401-15:47:01.276(-5)? (STDERR) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
W20150401-15:47:01.276(-5)? (STDERR) at packages/meteor/dynamics_nodejs.js:121:1
W20150401-15:47:01.276(-5)? (STDERR) at [object Object].urlencodedParser (/Users/Bechard/.meteor/packages/iron_router/.1.0.7.1oysnq2++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:69:27)
W20150401-15:47:01.276(-5)? (STDERR) at packages/iron:router/lib/router.js:277:1
W20150401-15:47:01.276(-5)? (STDERR) at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20150401-15:47:01.277(-5)? (STDERR) at [object Object].hookWithOptions (packages/iron:router/lib/router.js:276:1)
W20150401-15:47:01.277(-5)? (STDERR) at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1)
W20150401-15:47:01.277(-5)? (STDERR) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)

Now run moment() and you'll get an error instead of the correct output.

Looks like this might have been a problem with body-parser, or it could even be a problem in iron:router, just not sure.

Also, if any other projects are using body-parser: "1.12.2" you may never even get this error. I noticed once I upgraded a different project on my local computer to this version I couldn't reproduce the problem even on a my test project.

@glasser

This comment has been minimized.

Member

glasser commented Apr 1, 2015

This seems pretty complicated. I'm not sure where Stripe_Events comes from. If you can figure out a way to replicate it without meteorhacks:npm (which while a very useful package definitely is a non-supported way of using npm modules) and ideally without using iron:router that would be helpful.

@c316

This comment has been minimized.

c316 commented Apr 1, 2015

Ok, yea, pretty much the minute I posted my last post I exited the test project and immediately had the same issue again on my real project.

I'll do some more work here to try to replicate, it is really hard to pin down.

This is the error I get when moment() stops working in the shell, not sure if you can use it to help point me in the right direction or not.

TypeError: Property 'moment' of object # is not a function
at repl:1:2
at /Users/Bechard/Documents/meteor/give/.meteor/local/build/programs/server/shell-server.js:243:23

@c316

This comment has been minimized.

c316 commented Apr 1, 2015

@glasser I think I've figured out a better way to reproduce the error.

create a new meteor app
cd into it
meteor add momentjs:moment
meteor
in another terminal run meteor shell
moment()
This should output properly

now remove a smart package while the shell is open
in the shell try to run moment() again
This time it doesn't work

To fix the shell you have to stop the meteor app, then start meteor, then start the shell and it works again.

Just restarting the shell doesn't work. Also, I noticed that if I tried to restart the shell before meteor was completely started it stayed broken.

@artisonian

This comment has been minimized.

artisonian commented Apr 2, 2015

I've found a way to reproduce the issue with the Todos example app. If meteor shell starts before meteor, once it connects, moment will be undefined.

meteor create --example todos
cd todos
meteor add momentjs:moment
meteor shell

The server will be unavailable, so the shell tool will wait for a connection. In another terminal session:

meteor

Now, if you enter moment() in the shell, you'll get an error.

@glasser

This comment has been minimized.

Member

glasser commented Apr 2, 2015

@artisonian OK, I'm going to open this as a new issue because it's kind of different from the bug fixed above. #4109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment