Closed joneslloyd closed 8 years ago
Interesting indeed! You're enqueuing a single, webpack'd file, then, I take it? I'm perplexed as to why the lodash reference would be conflicting with anything. Are you defining aliases for _
anywhere in your webpack config, by any chance?
Yes! Re: The single webpack'd file. And only jQuery! Pretty odd...
On 26 Jul 2016 2:21 am, "K.Adam White" notifications@github.com wrote:
Interesting indeed! You're enqueuing a single, webpack'd file, then, I take it? I'm perplexed as to why the lodash reference would be conflicting with anything. Are you defining aliases for _ anywhere in your webpack config, by any chance?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/WP-API/node-wpapi/issues/193#issuecomment-235135439, or mute the thread https://github.com/notifications/unsubscribe-auth/AA84M-zRqBAnddK34RaS-5vWt8nM9gBJks5qZWEPgaJpZM4JUnS_ .
Ah, I wonder if it's related to this: https://core.trac.wordpress.org/ticket/35181 (Lodash needing to be put into noConflict mode due to Underscores conflicts) ?
Ah - solved it (for me) !
In:
/wpapi/lib/mixins/filters.js
/wpapi/lib/mixins/parameters.js
/wpapi/lib/constructors/wp-request.js
/wpapi/tests/integration/categories.js
I changed, in each instance, var _ = require( 'lodash' );
to:
var ld = require( 'lodash' );
var _ = ld.noConflict();
Now everything works perfectly :)
Awesome, thanks for the update. Lodash is going away in favor of individual Lodash sub modules in 0.9, so this ought not be a problem again in the future; but good to know what's the reason was!
Thanks for this guys. I ran into the same issue ~2 years later making use of lodash's pluck method in a React / Redux driven WP plugin. I was importing it -
import __ from "lodash";
I've been habitually setting "this" to _ in methods, probably from my Angular days, I thought this was the conflict initially. This fixed it:
import ld from "lodash";
let __ = ld.noConflict();
Huu! what a relieve thanks guys I've been fiddling with this error: "_.pluck is not a function" error" the whole day.
:grin: Glad this issue lives on and helps people!
Great JS client, and works really well.
One issue I've found is that when using it in the WP Editor area (as part of a JS-fuelled WordPress plugin using React), I get the following console errors:
and
I've extensively tested and turned everything else off/on, and only when I remove the node-wpapi library from my webpack file (therefore not including it in my project) do the above errors stop.