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.

Supporting documentation for Angular 2.x use / consider removing dependency

See original GitHub issue

Is your feature request related to a problem? Please describe. Integration of mermaid into an Angular 2.x project may result in an error like:

ERROR Error: Uncaught (in promise): ReferenceError: global is not defined
ReferenceError: global is not defined
    at Object../node_modules/node-libs-browser/node_modules/buffer/index.js (index.js:43)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/safe-buffer/index.js (index.js:2)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/randombytes/browser.js (browser.js:15)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/crypto-browserify/index.js (index.js:3)
    at __webpack_require__ (bootstrap:84)
    at Object../node_modules/crypto-random-string/index.js (index.js:2)
    at __webpack_require__ (bootstrap:84)
    at resolvePromise (zone-evergreen.js:797)
    at resolvePromise (zone-evergreen.js:754)
    at zone-evergreen.js:858
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:39679)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
    at Zone.runTask (zone-evergreen.js:168)
    at drainMicroTaskQueue (zone-evergreen.js:559)

This can be resolved by polyfill’ng adding the following to polyfills.ts:

(window as any).global = window; // gets rid of the first error
global.Buffer = global.Buffer || require('buffer').Buffer; // which leads to buffer being required
(window as any).process = { // which leads to window.process.version needing to be parsed
  env: { DEBUG: undefined }, // https://github.com/nodejs/readable-stream/issues/313
  version: 'v0.9.'
};
(window as any).setImmediate = window.setTimeout; // which leads to setImmediate being required

Note that all of this is due to ‘crypto-random-string’ which relies on ‘crypto’ which pulls in a bunch of wedges intended to emulate node libs in the browser, some of which still have issues without the above polyfills.

Describe the solution you’d like At a minimum, documentation for the polyfills above. Ideally, I’d remove or change out the crypt string library for a simpler dependency chain (which would also be smaller).

Thanks for the cool library!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arimuscommented, Nov 20, 2019

@chris579 Indeed. Oops! Was on a temp phone when I commented…and must have clicked the wrong button. That’s a first for me. My apologies!

0reactions
arimuscommented, Feb 25, 2021

This is not just an issue in IE. If I recall, crypto-random-string is a nodejs module and does not work in any browser. I was testing in chrome when I ran into this issue.

On Thu, Feb 25, 2021, 3:13 PM Justin Greywolf notifications@github.com wrote:

As #1175 https://github.com/mermaid-js/mermaid/issues/1175 was closed as “wont fix”, we should revisit this issue. Was this only an issue on IE11? Is this still something that needs to be handled?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/mermaid-js/mermaid/issues/1082#issuecomment-786262799, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXYKQVJT5MUYM7ZAXOXFLTA3DPTANCNFSM4JPJVXWA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular coding style guide
Looking for an opinionated guide to Angular syntax, conventions, and application structure? Step right in. This style guide presents preferred conventions ...
Read more >
Cheat Sheet - Angular
List of dependency injection providers visible both to the contents of this module and to importers of this module. bootstrap: [MyAppComponent]
Read more >
Security - Angular
This topic describes Angular's built-in protections against common web-application vulnerabilities and attacks such as cross-site scripting attacks.
Read more >
Upgrading from AngularJS to Angular
Pure AngularJS applications can be automatically bootstrapped by using an ng-app directive somewhere on the HTML page. But for hybrid applications, you manually ......
Read more >
Angular versioning and releases
The practices described in this document apply to Angular 2.0 and later. ... We update peer dependencies in minor versions by expanding the...
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