Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joshjuntilla's avatar

Vite and npm run dev

Hi guys, I would like to ask regarding Vite. I'm still new to it and trying to figure out this but maybe I'm just doing it wrong

My understanding is that when you run npm run dev you can run the dev server locally. The command runs okay without error and the local URL is working, however, when I check the URL, the link is only showing the default Laravel Vite page. I'm expecting it should show my Laravel project. So I'm not sure what I'm doing wrong or am I missing something in the settings?

0 likes
3 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Based on the description provided, it seems like the issue is that when running npm run dev with Vite, the default Laravel Vite page is being displayed instead of the expected Laravel project.

To resolve this issue, you need to make sure that you have properly configured Vite to work with your Laravel project.

Here are the steps you can follow:

  1. Make sure you have installed Vite globally by running the following command:
npm install -g create-vite
  1. Create a new Vite project in your Laravel project's root directory by running the following command:
create-vite

This will create a new Vite project in a separate directory.

  1. Once the Vite project is created, navigate to the Vite project directory by running the following command:
cd vite-project
  1. Install the required dependencies for the Vite project by running the following command:
npm install
  1. Build the Vite project by running the following command:
npm run build

This will generate the necessary files for the Vite project.

  1. Copy the generated files from the Vite project's dist directory to your Laravel project's public directory.

  2. In your Laravel project's resources/views/welcome.blade.php file, update the <script> tag to point to the Vite-generated JavaScript file. For example:

<script src="{{ asset('js/app.js') }}"></script>
  1. Finally, run the Laravel development server by running the following command:
php artisan serve

Now, when you access the local URL, it should display your Laravel project instead of the default Laravel Vite page.

Please note that these steps assume you have already set up Laravel and have a basic understanding of Laravel and Vite. If you are still facing issues, it would be helpful to provide more details about your project setup and any error messages you are encountering.

joshjuntilla's avatar

Hi. So I dig further and I think finally get it to work. So I guess I misunderstood how it should work. I thought that with Vite, you don't have to use the php artisan serve command but I got that wrong. Anyway, thank you for the responses

Please or to participate in this conversation.