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

Running on NodeJS #111

Open
SeanSobey opened this issue Nov 21, 2021 · 3 comments
Open

Running on NodeJS #111

SeanSobey opened this issue Nov 21, 2021 · 3 comments

Comments

@SeanSobey
Copy link

While running this plugin on NodeJS we are getting this error (running ChartJS via my lib):

(node:8700) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at afterBuildTicks (/home/../node_modules/chartjs-chart-financial/dist/chartjs-chart-financial.min.js:11:2437)
    at callback (/home/../node_modules/chart.js/dist/chart.js:800:15)
    at TimeSeriesScale._callHooks (/home/../node_modules/chart.js/dist/chart.js:5099:5)
    at TimeSeriesScale.afterBuildTicks (/home/../node_modules/chart.js/dist/chart.js:5115:10)
    at TimeSeriesScale.update (/home/../node_modules/chart.js/dist/chart.js:5037:10)
    ...

Obviously, the error is from the window reference. It looks to just be the one reference, when checking for Luxon, and it can be resolved via something like this:

afterBuildTicks: scale => {
        if (!('window' in this)) {
	        return;
        }
        const DateTime = window && window.luxon && window.luxon.DateTime;
        if (!DateTime) {
	        return;
        }
        ...

I am happy to test and submit this via pull request but am just inquiring about interest and appetite to support NodeJS with this fix and going forward?

@benmccann
Copy link
Collaborator

That sounds fine to me

@KooperL
Copy link

KooperL commented Jan 5, 2022

Really glad I found this, was ready to give up.
idk what I'm doing but I added to Sean's fix and pasted into chartjs-chart-financial.min.js and now I have pretty candlesticks saved from node :))

...afterBuildTicks:e=>{if(typeof(this)=='undefined'){return;}else{if(!('window' in this)){return;};};const t=window&&window.luxon&&window.luxon.DateTime;...

@SeanSobey
Copy link
Author

Created a pull request for this

@SeanSobey SeanSobey reopened this Jan 6, 2022
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