andredumas / techan.js

A visual, technical analysis and charting (Candlestick, OHLC, indicators) library built on D3.
http://techanjs.org/
MIT License
2.4k stars 536 forks source link

Uncaught TypeError: Cannot read property 'min' of undefined(…) #179

Open FredCHHsu opened 7 years ago

FredCHHsu commented 7 years ago

I am using webpack for bundling JavaScript. When I tried to import techan, I got this...

Uncaught TypeError: Cannot read property 'min' of undefined(…) techan.js:1424

I traced the code and found that was from "d3.min", I tried to directly import d3 and add techan.js to my project. Still keep receiving error. Any help?

briancappello commented 7 years ago

Are you using babel?

You could try

import * as d3 from 'd3';

but I wasn't able to get that working with events (even though the end of this thread suggests otherwise: https://github.com/d3/d3/issues/2733).

In the end, the only way I was able to get it working was to include d3 through a classic script tag, outside the flow of webpack. But perhaps you'll have better luck than I did?

FredCHHsu commented 7 years ago

@briancappello Yes, I am using import * as d3 from 'd3'; as you mentioned. Still can't make it work within webpack flow.

pixelami commented 7 years ago

I believe the problem is here https://github.com/andredumas/techan.js/blob/master/src/techan.js#L6 If window exists it insists on referencing d3 as a global.

adamrabie commented 7 years ago

@briancappello

I'm having same issue here but was able to attach it to the window with new webpack.ProvidePlugin({ "window.d3": "d3" }), in webpack conf

I still get the error Uncaught TypeError: Cannot read property 'sourceEvent' of null

Which is driving me a bit crazy. I've tried using modules individually instead of importing all of d3 and that didn't make a difference. Unfortunate because techan is only package i'm having this babel trouble with. I think its because of two includes of d3 one attached to the window but I cant remove it without techan thinking it doesn't exist.

a-hart commented 7 years ago

I am using https://github.com/SimulatedGREG/electron-vue which is just an electron vue boiler plate, however I was able to get it working with electron/webpack by adding:

....  extra code removed
plugins: [
new webpack.ProvidePlugin({
       d3: 'd3'
     })]

into webpack.renderer.config.js (webpack.config.js is where it normally would be I believe) and then in my index.html where the webpack bundle gets injected I put the following Githubissues.

  • Githubissues is a development platform for aggregating issues.