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.

d3 global now missing in electron

See original GitHub issue

First of all, thank you for this awesome library! I’ve learn lots of stuff under its hood and I was able to write a disk space visualization app fairly thanks to d3.

However, in the last npm updates, the d3 global is no longer defined in Electron. I currently include d3 in electron like

<script src="node_modules/d3/d3.js"></script>

I believe the change was caused by commit 1fad2e0cf7fba217eba0eadf3cae17c15090f1dd. Of course this could be Electron specific (it having both browser and node properties), and one workaround for me is to write

<script> var d3 = require('d3') </script>

Just checking if the current d3 behaviour is correct and whether you think my solution is sound.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
albertosantinicommented, May 8, 2016

At last, for my use case, I added "node-integration": false to BrowserWindow options, as suggested in https://github.com/electron/electron/issues/254

Now <script src="node_modules/d3/d3.js"></script> works nice in the usual browser env and electron one.

1reaction
albertosantinicommented, Jan 6, 2016

My use case is a bit different.

I have an express app: it works like a web app and an electron one.

When I start the app in electron environment, the global d3 object is not available. That is due to typeof module === "object" && module.exports is true.

main.js

...
require("./src/server/app"); // start the express app
...
mainWindow.loadUrl("http://localhost:8000");

index.html

...
<script src="https://cdn.rawgit.com/mbostock/d3/master/d3.min.js"></script>
...

As workaround I need to add the following line to the index.html

...
<script src="https://cdn.rawgit.com/mbostock/d3/master/d3.min.js"></script>
<script>if (typeof module === "object") { window.d3 = module.exports; }</script>

I suggest to add also this.d3 = d3 if window is defined in module part:

  if (typeof define === "function" && define.amd) 
      this.d3 = d3, define(d3); 
  else if (typeof module === "object" && module.exports) 
      module.exports = d3; 
      if (typeof window === "object") // new line
          this.d3 = d3; // new line
  else 
      this.d3 = d3;

or changing the condition for module case to enter in the last else part:

  else if (typeof module === "object" && module.exports && typeof window === "undefined") 

Does it make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

D3.js not defined with Electron - Stack Overflow
I am trying to pass on Electron my AngularJS application based on D3.js. The application works perfectly when I try it with Chrmoium...
Read more >
The Order of Filling 3d and 4s Orbitals - Chemistry LibreTexts
Each additional electron usually goes into a 3d orbital. ... The 4s electrons are lost first followed by one of the 3d electrons....
Read more >
Electron configurations of the 3d transition metals (video)
in the video " electron configuration for d block element" while ... the " missing " electron is instead located in the outermost...
Read more >
Electron app with custom protocol - Gleb Bahmutov
Create lightweight desktop application that can open custom protocol links (similar to iTunes itmss:// or Slack slack:// application links).
Read more >
How to Make Your Very First Desktop App With Electron and ...
If you restart the app, now you should see a “Hello World!” showing up. The default Svelte app. Unfortunately, if we make some...
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