Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

TypeError: window.TradingView is undefined #10

Open
AndriusDK opened this issue Mar 22, 2019 · 20 comments
Open

TypeError: window.TradingView is undefined #10

AndriusDK opened this issue Mar 22, 2019 · 20 comments

Comments

@AndriusDK
Copy link

AndriusDK commented Mar 22, 2019

Hello whenever I try to reuse the component TVChartContainer /> i get the following error TypeError: window.TradingView is undefined

@jonchurch
Copy link
Owner

jonchurch commented Mar 22, 2019 via email

@AndriusDK
Copy link
Author

The charting library isnt included, you need to download it separately from tradingview

On Fri, Mar 22, 2019 at 9:50 AM AndriusDK @.***> wrote: Hello whenever I try to reuse the component i get the following error TypeError: window.TradingView is undefined — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#10>, or mute the thread https://github.com/notifications/unsubscribe-auth/AMUR2_QQaIDG9ZoE_QH5JwXaOBPaDPCpks5vZN-ggaJpZM4cDnOn .

Hello again the thing is that I have the libraries included from the private repository. Just I have my webapp in react and I try to include your implementation files to my project.

@jianqiangsong
Copy link

TypeError: Cannot read property 'onready' of undefined
TVChartContainer.componentDidMount
C:/Users/Administrator/Desktop/test_tv/tradingview-js-api-tutorial/part2/src/components/TVChartContainer/index.jsx:58

@nicqchen
Copy link

nicqchen commented Apr 8, 2019

same error

@BStephenBB
Copy link

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

@AndriusDK
Copy link
Author

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

It works thanks!

@vnsfin
Copy link

vnsfin commented Jul 30, 2019

@BStephenBB can you please provide complete code as i am unable to make this working

@Albot15
Copy link

Albot15 commented Aug 1, 2019

Does anybody have a solution on this? I am also getting the same error "TypeError: window.TradingView is undefined".

I have included charting library.

@BStephenBB
Copy link

@vnsfin @drajvat See my comment above on how to get this working, I put the important lines of code there. I'm very busy right now, but can provide a full file-example later when I get the time if it's still not working for you guys.

@SatAndrei
Copy link

Can anyone post the line of importing the Widget?

@SatAndrei
Copy link

SatAndrei commented Aug 5, 2019

@rokoz77

Failed to compile
./src/components/TVChartContainer/index.jsx
  Line 61:  'TradingView' is not defined  no-undef
  Line 94:  'widget' is not defined       no-undef

Hei. I've tried to insert your solution in my index.jsx but i get that error. Can you please provide the whole file?

My index.jsx file looks like this:
https://pastebin.com/U6q2p8bw

@rokoz77
Copy link

rokoz77 commented Aug 5, 2019

You already have a widgetOptions so you don't have to add it
You only need to import tv.js lib
Maybe you need to download it

https://s3.tradingview.com/tv.js

Edit : sorry i'm talking about somethink else

@SatAndrei
Copy link

@BStephenBB
Hello.
I've tried your solution and posted my index.jsx and errors above. I can't figure out where to export the {widget} from.

@miky9585
Copy link

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

It works thanks!

using this into /src/components/TVChartContainer/index.jsx
import { widget } from '../../charting_library/charting_library.min.d.ts';
I have
TypeError: __WEBPACK_IMPORTED_MODULE_3__charting_library_charting_library_min_d_ts__.widget is not a constructor

What is wrong with my import?

@miky9585
Copy link

miky9585 commented Sep 17, 2019

I've solved. Maybe is useful for someone else.
Step 1) You need to copy charting_library into /src folder too (not only in public!)
Step 2) Put /* eslint-disable */ at the top of /src/chrating_library/charting_library.min.js
Step 3) Include widget with this code into /src/components/TVChartContainer/index.jsx
import { widget } from '../../charting_library/charting_library.min';
without extension
Step 4) put tvWidget = null; before componentDidMount()
Step 5) Remove everything start with "window.TradingView" and paste with this

const tvWidget = new widget(widgetOptions); this.tvWidget = tvWidget; this.tvWidget.onChartReady(() => { console.log('Chart has loaded!') });

@daveb1392
Copy link

@miky9585 Thank you soo much that fixed it

@TholeThilis
Copy link

Hi @miky9585 @daveb1392 I've been trying to follow the above steps but i don't seem to get it right, can you please. i'm definitely sure that my importing is not right. i need to get this charting library soon. i don't have experience in programming but i have learnt most of the things on the internet... we can even communicate through Skype or Teamviewer when necessary. Thank you.

@joesmith34625
Copy link

I followed jonchurch's part1 instruction, I got this error.
TypeError: window.TradingView.onready is not a function
after I replaced below line, it works
from
window.TradingView.onready(() => {
to
window.addEventListener('DOMContentLoaded',() => {

@amkamn
Copy link

amkamn commented Apr 8, 2021

Maybe is useful for someone else.

  1. public folder -> paste charting_library folder
  2. Charting Component ->
  const widgetOptions = {
   //some Widget options
  };
  let widget = null;
  widget = window.tvWidget = new window.TradingView.widget(widgetOptions);
}

3.   <div id='myID'  />

@sahilxjain
Copy link

In the recent version of charting library, charting_library.min.js is missing. I solved it by using charting_library.js instead.

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

No branches or pull requests