skip to Main Content

I’m currently working on a Vite Laravel 10 app and I’m facing an issue where both console.log and alert statements are not working.

I have the following code in my `resources/js/app.js

alert("hi");
console.log("hi");
import "./bootstrap";

I expect to see the alert dialog and the message "hi" logged to the browser’s console. However, neither of them are displaying any output.

Environment Details:

  • Operating System: WSL Ubuntu
  • PHP Version: 8.1.2
  • Laravel Framework Version: 10.15.0
  • Vite Version: 4.4.3

Troubleshooting Steps Taken:

  • Checked that the code is correctly placed in the resources/js/app.js file.
  • Verified that the bootstrap module is imported correctly.
  • Tried using both console.log and alert statements in different parts of my code.
  • Changed browsers to see if the issue persists.
  • Ensured that there are no filters applied in the Chrome console.
  • Checked all levels of output (verbose, info, warnings, errors) in the Chrome console.
  • Executed the npm run dev command to start the development server.

Despite these attempts, I’m still unable to see the alert dialog or the message "hi" logged to the browser’s console.

I would appreciate any insights or suggestions on how to resolve this issue. Thank you!

3

Answers


  1. Chosen as BEST ANSWER

    After I restarted my computer, every problem has gone...

    @vite('resources/js/app.js') works as expected and I can see the console.log and alert.


  2. Set a debugger; in your app js file, Then run your app. I think your app js file is not running.

    Note: open the console panel when you are running your app.

    Login or Signup to reply.
  3. Add this to your main laravel file:

    @vite(['resources/css/app.css', 'resources/js/app.js'])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search