Why npm run dev stuck on APP_URL? - laravel

Today when i tried to run npm run dev in Laravel 9 , it stucks at APP_URL line. Earlier there were no issues.enter image description here

Hope it's because of Vite
try with
npm run build

There is nothing wrong with your build. Laravel now uses Vite as front-end bundler. It is much more powerful than mix, so check out the documentation and get used to it. Or roll back to mix.

first solution : Laravel 9.19 replace the mixer with Vite, for Vite Configuration visit the official Doc of Laravel for Vite Bundling Assets (Vite)
second solution: install Laravel version 9.1.0 or lower
composer create-project Laravel/Laravel App_name 9.1.0

Uninstall and reinstall the npm package.
Delete the node_modules folder. and then run the following command
npm install
Later
npm install -g require

Related

Npm run dev stuck at APP_URL

I created a new laravel project, installed breeze auth and ran npm install and npm run dev. But it's stuck at this screen for 15 minutes now. Nothing is moving on the terminal window.
All the commands I used was
laravel new shop
composer require laravel/breeze
php artisan breeze:install
npm install
npm run dev
Everything worked fine until npm run dev, but when I enter npm run dev command, I get this output and nothing else.
PS C:\shop> npm run dev
> dev
> vite
vite v2.9.13 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 364ms.
Laravel v9.19.0
> APP_URL: http://shop.test
Laravel version 9.19.0 replaced Mixer with Vite for more information check Bundling Assets (Vite)
if you want to work mixer install Laravel version /= 9.1.0
composer create-project Laravel/Laravel app_name 9.1.0
I used npm run build instead npm run dev. And that solved it, I guess.
I faced the same problem. I tried for many hours to solve this problem. Laravel 9.19.0+ is using Vite to replace Laravel Mix for bundling assets. https://laravel.com/docs/9.x/vite#main-content
Starter kit components like Laravel Breeze and Jetstream have been using #vite
#vite(['resources/css/app.css', 'resources/js/app.js'])
When we run npm run dev vite will create own host below.
> dev
> vite
vite v2.9.13 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 364ms.
Laravel v9.19.0
> APP_URL: http://shop.test
And alway embed our style and script with this host http://127.0.0.1:3000/
<link rel="stylesheet" href="http://127.0.0.1:3000/resources/css/app.css">
<script type="module" src="http://127.0.0.1:3000/resources/js/app.js"></script>
I found a file name hot in the folder public was been created during we run command npm run dev and it is never delete.
To work around I just delete hot file by add few code into package.json
From
"scripts": {
"dev": "vite",
"build": "vite build"
},
To
"scripts": {
"delhot": "npx rimraf public/hot",
"dev": "vite",
"build": "npm run delhot vite build"
},
I hope that next release version of Laravel Vite will fix this issue.
composer create-project Laravel/Laravel app_name 9.1.0
Just use this laravel ver

Vuejs installed or not?

I am a beginner in Vuejs.I want to develop an application with laravel and Vuejs.I have follow the step of installing laravel and Vuejs and execute this composer create-project --prefer-dist laravel/laravel demo "5.8.*" command.I verify to check that Vuejs is installed or not by adding the extension of Vuejs in google chrome and it showing Vuejs is installed.But when i execute the command vue --version in the putty by connecting server through SSH then it shows error that "vue command not found".Why?
May be this question is not proper to ask but i am very confusing that actually Vuejs is installed or not.And is the Vuejs files structure is same or different?
Thanks in advance.
Installing and compiling vue into a laravel project is different than using the vue cli.
In Laravel, Vue is included in the assets registry in the package.json file.
npm uses this file to pull in assets then allows you to build them. It pulls them in with npm install
Note: you need node.js installed on your system.
The build commands you can see at the top of the package.json. They usually are:
npm run dev, npm run prod, and npm run watch.
Here is the documentation on getting started with Laravel and Vue:
https://laravel.com/docs/7.x/frontend

Error on Laravel after installing VueJS. Request failed with status 404

I am developing a small system with Laravel Framework 5.6.39 and everything was going well, until I installed Vue Js. When viewing in the browser, what should be displayed does not appear and the following appears in the console:
How can I solve this error?
I think you need to run:
npm run watch
After adding VueJS to your project you need to install all dependencies by executing:
npm install
Then you can either compile your assets onetime by executing:
npm run dev
Or start a watcher which compiles your assets automatically after detecting a filechange:
npm run watch
The compile process will generate the app.js file which is missing in your case. You can read more about this process or possibilities in laravel here (laravel docs about frontend).
After pulling your project you need to install all dependencies using
npm i
Then you can build it for development one-time using
npm run dev
Or for real-time updates
npm run watch
And when your project is ready for production
npm run prod

Laravel 6.0.3 Not Loading Key Resources App.js or App.css 404 Not Found

To setup my project I ran:
laravel new cms
composer require laravel/ui
php artisan ui:auth
php artisan migrate
However, when I go to http://cms.test/login I am shown the login page:
And get two 404 errors for missing resources:
http://cms.test/js/app.js net::ERR_ABORTED 404 (Not Found)
http://cms.test/css/app.css
What could be the reason for these missing files?
My public directory is empty aside from .htaccess, favicon.ico, index.php and robot.txt files, is that normal?
My setup was a little wrong, I mostly forgetting to run npm install and npm run dev command that is required to compile the app.js and app.css files.
Correct setup command sequence was:
laravel new cms
cd cms
php artisan migrate
composer require laravel/ui
npm install
php artisan ui vue --auth
npm install && npm run dev
The app.css and app.js were missing from a new app. The proper steps had been run as are noted in Jack Robson's answer above. I reran the last two steps:
php artisan ui vue --auth
npm install && npm run dev
And it generated the app.css and app.js - all good now.
No idea what had gone wrong in the initial install.
The below command did the trick for me.
npm install && npm run dev
In my case it was:
that when configuring the
Virtual Host in Apache wrote the path to the folder incorrectly:
DocumentRoot "D: \ LARAVEL \ instagrmalaravel \ public"
...
when on host it was:
127.0.0.1 instagramlaravel.local,
change: instagrmalaravel to: instagramlaravel.
And everything worked correctly.
The reason the files are missing is you forgot to run the build process that generates the files. The last command npm run dev does this. Having the 2 commands paired (npm install && npm run dev) in the docs seems to be catching a lot of people out.

Laravel project auto refresh after changes

Does anyone know if there is a way to run the code changes in a Laravel project without refreshing the page every time.
I know that to see the changes I need to
php artisan serve
but I do it every time and it is kind of frustrating.
Thank you anyways.
You can achieve this with Laravel Mix.
According to this part of the documentation, you need to edit your webpack.mix.js file, and add this to the end:
mix.browserSync('127.0.0.1:8000');
It needs to match to the output of the php artisan serve command, where you found a line something like this:
Laravel development server started: <http://127.0.0.1:8000>
After this, you have to run the php artisan serve, and the npm run watch command simultaneously. You must leave to run both commands while you edit your files.
Note: The first time you run the npm run watch, it installs additional components. But the command output is quite clear on that. If everything is in order, Laravel Mix automatically opens your browser with http://localhost:3000, or something like this.
add in webpack.mix.js file in laravel
mix.browserSync('127.0.0.1:8000');
then run this command
> npm install browser-sync browser-sync-webpack-plugin#2.0.1 --save-dev --production=false
after this run npm run watch
> Browsersync automatic run your port 3000
First make sure you install nodejs, After that install laravel-mix
npm install --save-dev laravel-mix
create webpack.mix.js file in root folder for your project and add to it
const mix =require('laravel-mix')
mix.browserSync('127.0.0.1:8000');
Open package.json file and add to script section:
"scripts": {
"watch": "mix watch"
}
Run laravel project
php artisan serve
To update laravel project auto when you make changes run in another terminal:
npm run watch
Updated from Laravel 9.x
you can use vite instead of laravel-mix, you should run this command to install vite:
npm install
Without any configuration, The next line of code will include auto in master page, If you want to include in another master page like admin, you can write it to auto refresh when make changes:
#vite(['resources/sass/app.scss', 'resources/js/app.js'])
After installing vite, run this command
npm run dev
And run
php artisan serve
For more information, view docs
To achieve this you can use Laravel Mix
Ensure that Node.js and NPM are installed:
run node -v and npm -v.
Install Laravel Mix
npm install.
Install browser-sync and browser-sync-webpack-plugin
npm install browser-sync browser-sync-webpack-plugin --save-dev --production=false
Open webpack.mix.js and add this line
mix.browserSync('127.0.0.1:8000');.
Run Project with these two commands: The npm run watch command will continue running in your terminal and watch all relevant CSS and JavaScript files for changes. Webpack will automatically recompile your assets when it detects a change
php artisan serve. and then npm run watch.

Resources