1

Orignal Link

I'm trying to call an external JS function which my 3rd party required me to include, in order to use their API, but doesn't work as it supposed to.

From what I've read, I am supposed to use, for example, window.extFn() after including the external JS in my index.html which contains the extFn() like so

...and supposed to use it like how it was answered here: Call external Javascript function from react components regardless of whether the said function is inside a file or simply defined on index.html section. This had worked on the JS file I created for testing this.

//File: test.js
function test() {
    return "Hello";
}

...imported the JS file with script tag like usual, and using console.log(window.test()) in my React Component's render() returned Hello.

I tried moving the import to HTML head from body and vice-versa but the error I'm still getting is:

TypeError: window.extFn is not a function
QuickCheckout.render

    ....
      22 |    }
      23 | 
      24 |    render() {
    > 25 |        window.extFn({
      26 |            
    View compiled
    ▶ 20 stack frames were collapsed.

And when I look into my browser console, for some reason I have (which seems to be the key problem)

Uncaught SyntaxError: Unexpected token <                                     external.js:1

my test.js file above, which had worked in my experiment, produces the Unexpected token < error as well in my console...

imported the JS from local source :

<script type="text/javascript"language="javascript"src="../src/external.js"></script>

this is the sample of external.js

function Initialize() {
    try {

        if (abc !== null) {

        }

        /*  if
         provide the call backs */
        abcd = new DEGD(
            a,
            b,
            c,
            d
        displayProgress('Initializing web socket...');
    } catch (e) {

        alert("Initialization Failed" + e);
    }
}

1 Answer 1

0

you can see the source in chrome devtools and check whether the external.js file is imported successfully

Sign up to request clarification or add additional context in comments.

5 Comments

I did check its 200 "Request URL: localhost:3001/src/external.js Request Method: GET Status Code: 200 OK Remote Address: 127.0.0.1:3001 Referrer Policy: no-referrer-when-downgrade"
Hi, @2239559319 If you have any idea what causing this, please let me know, I'll really appreciate.
can i see your external.js file and project structure?
I Can't its from 3rd party lib as I don't want to violate their regulations.
I've added sample of external.js , please chack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.