MooseSaid's avatar

Why can't I run 'npm run dev' after Taylor updated Laravel with Vite?

Taylor Otwell announced that new Laravel projects now will run with Vite and that Vite is installed by default. I can't seem to be able to run dev environment 'npm run dev'

I installed new laravel project, installed Laravel JetStream with SSR and teams support hit the 'npm install command'.

Every time I run npm run dev it shows this: error

And if I open the local link, it shows this: localhost

Why can't I user npm run dev and compile my files?

This is package.json for my brand new laravel app

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build && vite build --ssr"
    },
    "devDependencies": {
        "@inertiajs/inertia": "^0.11.0",
        "@inertiajs/inertia-vue3": "^0.6.0",
        "@inertiajs/progress": "^0.2.7",
        "@inertiajs/server": "^0.1.0",
        "@tailwindcss/forms": "^0.5.2",
        "@tailwindcss/typography": "^0.5.2",
        "@vitejs/plugin-vue": "^2.3.3",
        "@vue/server-renderer": "^3.2.31",
        "autoprefixer": "^10.4.7",
        "axios": "^0.25",
        "laravel-vite-plugin": "^0.2.1",
        "lodash": "^4.17.19",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.1.0",
        "vite": "^2.9.11",
        "vue": "^3.2.31"
    }
}

and if I try hitting 'vite' in the terminal I get this:

vite error

0 likes
25 replies
Snapey's avatar

Why localhost:3000 and not just localhost?

run npm build if you just want the assets and no server ?

1 like
MooseSaid's avatar

@Snapey It has been always localhost:3000 by default, I didn't change anything it's only after Taylor Otwell announced that Laravel new projects will use Vite and it stopped working.

So 'npm run dev' stopped working?

Snapey's avatar

@MooseSaid looks to be working in your screenshot

were your assets compiled?

do you have another webserver running on port 3000

when you try and browse to localhost:3000 is vite still running?

1 like
MooseSaid's avatar

@Snapey no assets gets compiled and nothing is running on another prot. Actually any laravel project that I have works fine and I can run npm run dev normally without issues. It really drives me crazy I mean without changing nothing if i Install a previous version everything works fine.

Snapey's avatar

@MooseSaid so, your assets are compiled, the only problem is you don't have a running webserver?

1 like
MooseSaid's avatar

@Snapey no nothing works, assets not compiled.

When I run npm run watch it shows me the first screenshot and none of them works and before Vite this isn't supposed to happen! Npm run dev should only compile my assets and that's it. And after that I would run php artisan serve and that gives me my working server but not assets are not compiled and npm run dev gets me this weird response in the first screenshot.

1 like
Sinnbeck's avatar

@folium Be aware that vite does not output files in "dev" mode. It runs a server that serves the needed files, and injects the css/js into the page.

Sinnbeck's avatar

Vite works by running a dev server. Show your vite config file. And show us what error you get in the browser console

MooseSaid's avatar

@Sinnbeck This is a brand new laravel app just installed even without breeze or jetstream, I installed it via composer then I ran npm install. when I run npm run dev I get this:

err

Opening http://localhost:3000/ gets me this: local err

and opening http://localhost gets me this: err2

Here is my package.json file

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "axios": "^0.25",
        "laravel-vite-plugin": "^0.2.1",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "vite": "^2.9.11"
    }
}

here is my vite.config.js file

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/js/app.js',
        ]),
    ],
});
1 like
MooseSaid's avatar

@Sinnbeck Running php artisan serve opens my project normally but without any compiling.

Sinnbeck's avatar

@MooseSaid You need both. npm run dev only runs a webserver for compiling your css/js.

1 like
MooseSaid's avatar

@Sinnbeck This is what I get in the console when running npm run dev and open localhost:300/

err

MooseSaid's avatar

@Sinnbeck So I need to run npm run dev and php artisan serve? is it like npm run watch previously? keeps an eye on any changes and compiling your assets while working?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@MooseSaid Yes. Its not a website you can use for anything yourself. It is just sites that vite uses. You can see the content here: http://127.0.0.1:3000/resources/css/app.css

But like I said, start php artisan serve as well, and enter that page. Now change some js/css and reload and see if it works.

1 like
indexed_dk's avatar

I have the exact same issue here.

I followed this guide from Taylor:

  • laravel new breeze-test
  • composer require laravel/breeze
  • php artisan breeze:install vue
  • npm install
  • npm run dev

I made sure breeze.test was available and working.

also tested out setting the server in the vite config:

export default defineConfig({
    server: {
        host: 'breeze.test'
    },
Sinnbeck's avatar

@indexed_dk Yeah you cannot see the root. You can only see the "endpoints". For example: http://127.0.0.1:3000/resources/css/app.css

Be aware the it will show the uncompiled version. The compiled version is still used on the page.

What I was talking about, is if you get an error in the browser console, when you are on the page.

Maybe consider making your own thread, so @moosesaid dont get an email for each time we reply to each other.

folium's avatar

@indexed_dk it seems like he wan't to get rid of this errors and try old one if in case that's why i attched this reply here.

Sinnbeck's avatar

@folium Seems that it might be working now :)

I will happily help others get theirs working as well, but I suggest creating new threads, so I can focus on one issue at a time

1 like

Please or to participate in this conversation.