2

I'm getting some odd behaviors loading breezejs in an application that also uses requirejs.

The main issue is that if I setup require to load breeze (plus its dependencies q and jquery), breeze fails to load unless knockout is setup as a dependency of breeze.

Uncaught Error: Module name "ko" has not been loaded yet for context: _. Use require([])

That's fine if I actually wanted to use knockout, but I'm using angular. I guess it doesn't break anything to load knockout too, but it's a waste of time to download if it's never going to get used.

So, my first question is why does breeze require knockout just because I'm using requirejs? Seems like a bug to me.

The other odd behavior WRT breeze and require is that if I load require and then breeze without using require, then breeze fails to load.

Uncaught Error: Mismatched anonymous define() module...

Seems that breeze makes the assumption that if require is loaded, that breeze will be loaded by require. But, this seems like a leap to assume. I ran into this issue since I first discovered the previous issue. I thought I'd just load breeze myself instead of having require do it. Of course, was still loading require since other parts of the app rely on require.

So, my second question is why does breeze have to be loaded before require? Just seems odd since the two libraries don't depend on each other. Why is there a required load order?

4

1 回答 1

0

From breeze website:

Breeze depends on one 3rd party JavaScript library, Q.js, which is included in the NuGet and download packages. Q.js is a popular implementation of the Common.js promises standard for managing asynchronous JavaScript.

This means that if you loaded Q.js it may conflict with requirejs, because it's just different implementation of AMD loader.

Also:

Except as noted, the other samples also require these libraries and they load the jQuery and Knockout scripts before the Q and Breeze scripts. Make sure you either follow their lead ... or know why you're doing it differently.

You should be able to configure to get away without knockout. Here is what's in their source code:

Possible options are 'ko', 'backingStore' or 'backbone'. See the breeze.config.initializeAdapterInstances method.

http://www.breezejs.com/sites/all/apidocs/classes/config.html

Hope this helps.

UPDATE: Looking at breeze source I see if require loader exists, they will try to load knockout as 'ko'. You shoulb be able to configure requireJS loader to work around this by defining your own 'ko' module that does not return anything or returns false. Then breeze will fallback to "backingStore" and it should not complain about it.

UPDATE BY WARD (20 MAY 2013): We'll have this fixed in the version after v.1.3.3. Please refer to this more recent S.O. where we provide temporary advice and will announce the fix.

于 2013-05-02T03:04:19.307 回答