skip to Main Content

I am using firebase for my web project. I have configured the firebase app and then imported the js script where I configured the app into my html doc as a type=module then I have written a function signUp() in the js file. I have added a button in the html doc with onClick = "signUp()" (this has worked for me in all of my past project where I used the old firebase SDK), but I’m getting an error that can't find variable signUp()

JS FILE:

enter image description here

HTMl Code (button and importing app.js)

enter image description here

The error

enter image description here

I have imported the app.js file as a module since importing the firebase modules requires me to do so and it won’t/doesn’t work without importing app.js as a type module

I also tried moving the function to another separate file but then there I dont have access to the createUserWithEmailAndPassword and other function so that’s also not working

Your help would be greatly appreciated!

2

Answers


  1. Try adding this to your app.js under your signUp() function

    window.signUp = signUp
    
    Login or Signup to reply.
  2. if you don’t want add it to the global scope like @PanhaBot’s suggestion. just setup the click event in the app.js. If you need to reuse the fireBase stuff else where, put that into a separate module and import that into app.js.

    const b = document.querySelector('#myButton');
    b.addEventListener("click", signUp);
    
    <button id="myButton"></button>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search