andredumas / techan.js

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

using techan as an AMD module, get error #219

Open overwatch13 opened 6 years ago

overwatch13 commented 6 years ago

Hi, is it possible to use techanjs when using requireJS?

Upon initial load immediately get this error. techan-error

briancappello commented 6 years ago

Have you tried the solutions in this issue?

overwatch13 commented 6 years ago

Hi Brian, I did see that post, but I am not using web pack or babel. Although I am not opposed to using babel, is it required for this thing to run? Could I pay you to help me take a look at this thing?

On Thu, Feb 22, 2018 at 7:36 AM, Brian Cappello notifications@github.com wrote:

Have you tried the solutions in this issue https://github.com/andredumas/techan.js/issues/179?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andredumas/techan.js/issues/219#issuecomment-367667451, or mute the thread https://github.com/notifications/unsubscribe-auth/AIHyX8ZoKbYLJNahvMDtep-9xp_3UjJAks5tXV9pgaJpZM4SOncl .

-- William Howley [c] 508-314-1199

ccancellieri commented 6 years ago

Guys take a look to the https://github.com/andredumas/techan.js/pull/220 hope this helps I've created a branch on my fork called modules to be able to use techan as ES6 module in my project. Since I don't think the pull request will be included I've checked out that branch to a subfolder of my project and then simply: import { techan } from './techan/techan';

llach commented 6 years ago

@overwatch13 had the same issue as you did. i ended up cloning this repo and editing the src/techan.js.

First, remove the following lines:


// If running in browser (window !undefined), assume d3 available
if('undefined' != typeof window) _d3 = window.d3;
else if('object' == typeof module) _d3 = require('d3'); // else we're in the only other supported mode: v8/node
else throw "Unsupported runtime environment: Could not find d3. Ensure defined globally on window, or available as dependency.";

Then change

var _d3;

to

var _d3 = require('d3');

Generate dist/techan.js anew and require it. Done!

JS really is annoying when it comes to conventions. Hope this lib is worth it.

slavikdenis commented 6 years ago

This solved the problem for me: https://github.com/andredumas/techan.js/issues/179#issuecomment-374907499