mattkrick / cashay

:moneybag: Relay for the rest of us :moneybag:
MIT License
453 stars 28 forks source link

String.prototype.startsWith: "undefined is not a constructor" #136

Open dustinfarris opened 7 years ago

dustinfarris commented 7 years ago

I'm running acceptance tests in Ember. The tests pass in Chrome, however when I run the tests in Phantom JS, I am getting this error:

TypeError: undefined is not a constructor (evaluating 'type.startsWith('@@cashay')')

which seems to stem from this line:

https://github.com/mattkrick/cashay/blob/27320c4ebd5c5d2ce697479d21a72de7f3d7c73c/src/normalize/duck.js#L38

Any idea what might cause this?

mattkrick commented 7 years ago

Did you set up the redux store for your tests?

On Oct 31, 2016 9:18 AM, "Dustin Farris" notifications@github.com wrote:

I'm running acceptance tests in Ember. The tests pass in Chrome, however when I run the tests in Phantom JS, I am getting this error:

TypeError: undefined is not a constructor (evaluating 'type.startsWith('@@cashay')')

which seems to stem from this line:

https://github.com/mattkrick/cashay/blob/27320c4ebd5c5d2ce697479d21a72d e7f3d7c73c/src/normalize/duck.js#L38

Any idea what might cause this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjvzlg9SpBdX7iO2aQU7o_PtLkLUtZks5q5hS4gaJpZM4KlM5O .

dustinfarris commented 7 years ago

Think I figured it out. It is because PhantomJS does not support String.prototype.startsWith. I am trying to find a polyfill I can inject.

mattkrick commented 7 years ago

Whoa! Thats interesting. I could use indexOf, startsWith is just a little more expressive

On Oct 31, 2016 10:33 AM, "Dustin Farris" notifications@github.com wrote:

Think I figured it out. It is because PhantomJS does not support String.prototype.startsWith. I am trying to find a polyfill I can inject.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136#issuecomment-257362422, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjv1OfRk6TKOe6-9DV5p8klsIKYHkvks5q5iaBgaJpZM4KlM5O .

dustinfarris commented 7 years ago

Here's a polyfill you could add to cashay's dependencies: https://github.com/mathiasbynens/String.prototype.startsWith

dustinfarris commented 7 years ago

But now getting the same thing for Object.prototype.find

e.g.: https://github.com/mattkrick/cashay/blob/8d9174d478b63883f68b64f82c183b60a3aad0c4/src/normalize/denormalizeStore.js#L56

This may be something I as a user should be responsible for polyfilling (I wonder if babel polyfill would make all of this go away).

dustinfarris commented 7 years ago

Yeah, running everything through babel polyfill makes this all go away.

This can be closed as far as I'm concerned, unless there is any docs action you think would be appropriate.

dustinfarris commented 7 years ago

I am hitting this again, this time in plain-ol node

var transformSchema = require('cashay').transformSchema;

transformSchema(myRootSchema...

results in

TypeError: undefined is not a function
    at /Users/dustin/Archive/broccoli-cashay-schema/node_modules/cashay/lib/schema/transformSchema.js:127:23

stemming from: https://github.com/mattkrick/cashay/blob/master/src/schema/transformSchema.js#L39

mattkrick commented 7 years ago

ah, now that we don't have the polyfill, it doesn't have startsWith?

dustinfarris commented 7 years ago

Correct—if I install/require the polyfill mentioned above everything works. What do you think about doing this in cashay instead?

Add String.prototype.startsWith to dependencies and in index.js:

import 'string.prototype.startsWith';

(not sure how the dots in the name will affect import)

and/or via babel-polyfill (again) — but it would be a devDependency this time just to generate lib/

dustinfarris commented 7 years ago

Well the fact that I was using node v0.12.6 probably wasn't helping 👎

What minimum version of node do we want to support?

mattkrick commented 7 years ago

I'd say 6 LTS, although I think 4 would work

On Nov 25, 2016 11:24 AM, "Dustin Farris" notifications@github.com wrote:

Well the fact that I was using node v0.12.6 probably wasn't helping 👎

What minimum version of node do we want to support?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mattkrick/cashay/issues/136#issuecomment-263013660, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQjv5tJpz05i337_BywMyy2l_yqHsq9ks5rBzXogaJpZM4KlM5O .