TypeError: window.TradingView is undefined
AndriusDK opened this issue · 20 comments
Hello whenever I try to reuse the component TVChartContainer /> i get the following error TypeError: window.TradingView is undefined
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.
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
same error
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!
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 usingtvWidget = 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!
@BStephenBB can you please provide complete code as i am unable to make this working
Does anybody have a solution on this? I am also getting the same error "TypeError: window.TradingView is undefined".
I have included charting library.
@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.
Can anyone post the line of importing the Widget?
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
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
@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.
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 usingtvWidget = 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?
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!') });
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.
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',() => {
Maybe is useful for someone else.
- public folder -> paste charting_library folder
- Charting Component ->
const widgetOptions = {
//some Widget options
};
let widget = null;
widget = window.tvWidget = new window.TradingView.widget(widgetOptions);
}
3. <div id='myID' />
In the recent version of charting library, charting_library.min.js is missing. I solved it by using charting_library.js instead.