3

I am trying to convert a project from SystemJS to WebPack which is using breeze-client and datajs (for OData support). In total, this is an angular2 application, so breeze-bridge-angular2 is also part of the project.

While the SystemJS version runs fine, the WebPack version throws an error:

Unable to initialize OData. Needed to support remote OData

Apparently, the issue is that breeze-client is unable to find the OData library in global.window.OData. Some quick debugging shows that the root cause appears to be that "global.window" is generally undefined (in function __requireLibCore). Note that datajs is appears to be correctly included in webpack, so the issue is not a missing datajs, rather breeze-client not being able to access "window" in general.

Debug Details

I am pretty new to the entire topic, so I am struggling to identify the correct solution. I believe something needs to be configured in webpack to make this work, but I am not sure what this something could be - my apologies for being vague here - perhaps some imports-loader or ProvidePlugin reference in webpack.config.js.

Any help would be much appreciated.

user1211286
  • 681
  • 5
  • 17
  • try using ProvidePlugin. it makes variable available at global level – nikhil mehta Dec 13 '16 at 12:23
  • As stated, that is what I am guessing. However, I have no clue what exactly to put into ProvidePlugin to make this specific case work. To make things more complicated, breeze-client does not access "window.OData" statically, but window[libName] with libName="OData". – user1211286 Dec 13 '16 at 12:46

1 Answers1

1

I had the same problem and used webpacks importsloader to solve this issue. It allows you to inject a variable into a module. More info here

Heres the snippet from my webpack config:

        { test: require.resolve('breeze-client/breeze.debug'), loader: 'imports-loader?this=>window,global=>{window: this}'},
Pantani
  • 1,223
  • 1
  • 18
  • 25