question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack and angular-cli support

See original GitHub issue

Breeze wraps its definition in a function and sees “this” as its global variables. For my understanding, this does not work in combination with angular-cli. angular-cli uses uses webpack and it looks like “this” is an empty object instead of the global namespace when using webpack. The result is, that breeze is unable to find any depending library like OData (datajs).

My (very) dirty fix: breeze.debug.js ` (function (global, definition) { var def = function(){ return definition(global); };

// CommonJS
if (typeof exports === "object" && typeof module === "object") {
    **global = window;**
    module.exports = def();
    // RequireJS
} else if (typeof define === "function" && define["amd"]) {
    define(def);
    // <script>
} else {
    breeze = def();
}

})(this, function (global) { … `

I found some other workarrounds in combination with webpack, e.g. this: http://stackoverflow.com/questions/41119357/how-to-configure-webpack-to-support-global-window-for-breeze-clientdatajs

The problem with angular-cli is, that it does not and will not expose the webpack configuration, so this is no solution.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
coni2kcommented, Sep 12, 2018

@marcelgood, I also had the same issue when using Angular CLI with BreezeJS & datajs.

in __requireLibCore function, it’s checking the availability of the necessary libraries by using global.window but somehow in Angular CLI project, global is just an empty object at that point and it throws Unable to initialize OData. Needed to support remote OData services error.

I just created a demo project that solves the issue by tweaking breeze.base.debug.js itself, which is of course not the proper way of fixing it: https://github.com/forCrowd/Labs-AngularCLI-BreezeJS

Also I had to modify package.json to refer to breeze.base.debug.js instead of breeze.debug.js.

“Readme” also contains how to see the error but let me know if you encounter any issue.


Update: Created a separate issue and updated the demo app Issue: https://github.com/Breeze/breeze.js/issues/221 Demo app: https://github.com/forCrowd/Labs-AngularCLI-BreezeJS

1reaction
MikaelLambertcommented, Nov 28, 2018

@coni2k thanks! This solution worked for me. It’s not the best to have to live patch a library like this, but it’s better to do this than to modify breeze-client directly.

@marcelgood I believe this rollup PR if completed would fix this problem and you should be able to update to the latest rollup and solve this problem properly.

https://github.com/rollup/rollup/pull/2274

Edit: I had some issues with Q even with this change and had to set it later. If someone runs into the same issue, try adding the following to your initialization:

import * as Q from 'Q';
import { config } from 'breeze-client';
config.setQ(<any>Q);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Custom webpack Configurations with Angular ...
The Angular CLI can create a new Angular project and it will handle the webpack configuration. However, there are situations where you will ......
Read more >
angular-cli where is webpack.config.js file - Stack Overflow
There's a nice way to eject webpack.config.js from angular-cli. Just run: $ ng eject. This will generate webpack.config.js in the root folder of...
Read more >
How to Customize Your Angular Build With Webpack
This tutorial shows how to use Angular's custom webpack builder to extend and customize your build process.
Read more >
Angular CLI vs. Custom Webpack Setup | by Pavlo Glazkov
Angular CLI does support defining multiple applications in the apps section of .angular-cli.json , but all the CLI commands work only with one ......
Read more >
JavaScript Frameworks: Angular CLI and Webpack
The advantages of Webpack in Angular are to perform many additional tasks and to support multiple nodes. Hence, it is highly expansible via...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found