vite-plugin: Configuration "resources/js/app.js" does not exist.

  • Laravel Vite Plugin Version: 0.2.0
  • Laravel Version: 9.19.0
  • Node Version: 18.4.0
  • NPM Version: 8.12.1
  • Inertia Version: 0.6.3

Description:

Upon running npm run dev Laravel throws:

Configuration "resources/js/app.js" does not exist.

Steps To Reproduce:

  1. Follow the official Laravel docs
  2. Replace ‘mix’ directive with ‘vite’ directive in app.blade.php

Went so far as to make changes in the vite.config file with no success. Also used an absolute URL for the resources and error persists.

Dumped composer and cleared Laravel and browser cache with no success.

There is a post on Stackoverflow with a similar issue: https://stackoverflow.com/questions/72799267/why-laravel-vite-directive-not-working-in-my-project

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (11 by maintainers)

Most upvoted comments

Thank you for sharing these. I can now see the issue you are facing.

You currently have the community Vite plugin and the Laravel plugin active, and they are conflicting with each other.

The PHP package "innocenzi/laravel-vite" along with the NPM package "vite-plugin-laravel" are part of the fantastic community Vite plugin.

This is a great plugin that has many features and you may wish to continue using it. If you do want to use the community plugin, I recommend uninstalling the "laravel-vite-plugin" NPM package.

Then you should refer to the documentation: https://laravel-vite.dev/

Alternatively, if you would like to use framework version, you should uninstall the "innocenzi/laravel-vite" composer package and additionally uninstall the "vite-plugin-laravel" NPM package.

Ensure that you have only followed the steps in the official upgrade guide.

Finally, if you are still having issues, you may need to run:

php artisan view:clear

to bust the view cache. I hope that gets you back on track.

Hehe, i just got the error on the developement project - same code as the one on production , which was live for a few months now - and i couldn’t understand why.

After i made the upgrade from webpack to vite, i forgot to delete the generated views from blade ( php artisan view:clear ) which was using the app.js from public folder…

The @vite() accepts as a paramter the config name from configs/vite.php file - so it is not correct to use @vite('resources/js/app.js') ( laravel mix was using the path of the files… ) but instead use @vite('default') or just @vite() - since in the code of Innocenzi / Vite you will find this line: $name ??= config('vite.default'); - so if you don’t set a name it will get the vite.default confing by default.

So when you migrate from webpack to vite on InertiaJS - just clear your views generate by laravel ( php artisan view:clear - or manually delete the storage/framework/views folder )

The below threw an error stating it had to be a string, not an array:

@vite(['resources/css/app.css', 'resources/js/app.js'])

So I changed mine to:

@vite('resources/js/app.js')

and got the error.

I also tried:

@vite('/resources/js/app.js') and an absolute url: @vite('http://dev.test/resources/js/app.js')

I’m using Valet hence the .test domain.

Yes, the app.js file exists and is in the correct location. Hmm… I get an htmlspecial characters error and indicating it has to be a string.

Let me revert back to mix and then migrate again over to Vite to see if anything gets resolved.