Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d4.js:1172 Uncaught ReferenceError: d4 is not defined #42

Open
martinlendable opened this issue Feb 25, 2016 · 3 comments
Open

d4.js:1172 Uncaught ReferenceError: d4 is not defined #42

martinlendable opened this issue Feb 25, 2016 · 3 comments

Comments

@martinlendable
Copy link

Trying to use d4 with reactjs::

Getting: d4.js:1172 Uncaught ReferenceError: d4 is not defined


import React from 'react';
import ReactDOM from 'react-dom';
import ReactFauxDOM from 'react-faux-dom';

import d3 from 'd3';
import d4 from 'd4';

class App extends React.Component {

render () {
const data =
[
{x: "For Investment", y: 13.27},
{x: "For Distribution", y: 8.66},
{x: "Outstanding Principal", y: 5.22},
{x: "Accrued Interest", y: 5}
];

const myChart = d4.charts.column().width(500)

const d = d3.select(ReactFauxDOM.createElement('div'))
.datum(data).call(myChart);

return d.node().toReact()

}
}
export default App;

@heavysixer
Copy link
Owner

Hi @martinlendable, Unfortunately I have no React experience. Is the Component a closure because if so maybe you need to pass the reference of d4 to it.

@dylansmith
Copy link

dylansmith commented May 16, 2016

This is not a React issue, but rather an issue with the way that D4 is internally reliant on the presence of a d4 global. I suspect if @martinlendable is using React and getting this error then it's because he's using webpack to build his code, and it fails at

d4/d4.js

Line 1176 in 1182dda

d4.helpers = {};
when webpack processes the import/require statement. I have the same issue in my Angular 1 codebase, using webpack as a builder.

@dylansmith
Copy link

@martinlendable as a workaround, you can use https://github.com/webpack/script-loader: require('script!d4');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants