martinandert / counterpart

A translation and localization library for Node.js and the browser.
MIT License
242 stars 25 forks source link

Uncaught ReferenceError: isPlainObject is not defined #18

Closed delacruz-dev closed 9 years ago

delacruz-dev commented 9 years ago

Hi,

I'm having an issue using counterpart with webpack. When doing:

import counterpart from 'counterpart';

It fails with Google chrome with the following error:

Uncaught ReferenceError: isPlainObject is not defined

When I open the web developer tools console and reload, it works. It only works with the developer tools open, but fails again when I close it. It doesn't fail in Firefox or Safari.

Do you have any ideas about what may be causing this issue?

Thanks in advance

martinandert commented 9 years ago

It's hard to tell what is actually going wrong here. Could you provide a stripped-down sample app that I could try out in order to reproduce this behavior?

greelgorke commented 9 years ago

see https://github.com/justmoon/node-extend/issues/31 and https://github.com/justmoon/node-extend/pull/32

have the same issue. it has something to do with how eval and strict mode are working, and webpack uses the eval for speed

martinandert commented 9 years ago

@greelgorke So this seems to be an issue when using node-extend and counterpart together with webpack, am I right? Will your node-extend 'strict mode' PR "fix" this counterpart issue then?

delacruz-dev commented 9 years ago

@greelgorke @martinandert sure, I've uploaded a test repo: https://github.com/danderu/counterpart-test

Just importing counterpart in my component makes it crash. It isn't working with @martinandert 's fix for me

greelgorke commented 9 years ago

@martinandert i've applied it manually in my local project and it solved it

martinandert commented 9 years ago

@danderu I've tried your test repo and can reproduce this issue now.

Counterpart depends on node-extend ^2.0.0 which, as @greelgorke pointed out (thanks!), does not utilize the 'use strict' pragma correctly. When @greelgorke's PR is applied and node-extend v2.0.2 is released, simply reinstalling the counterpart package should fix this issue. Until then, applying @greelgorke's patch in app/node_modules/counterpart/node_modules/extend/index.js fixed it for me, too and your test repo run fine in chrome.

delacruz-dev commented 9 years ago

@greelgorke @martinandert You are great! It's fixed now, thanks :) :+1:

greelgorke commented 9 years ago

@danderu @martinandert it's merged, but as a breaking change, so your ^2.0.0 might not be enough

martinandert commented 9 years ago

I just published counterpart v0.16.8 which depends on node-extend ^3.0.0.