laravel / vite-plugin

Laravel plugin for Vite.
MIT License
799 stars 151 forks source link

Vite dev server exits without message (fix in report) #15

Closed ericwang401 closed 2 years ago

ericwang401 commented 2 years ago

Description:

When running the Vite dev server using npm run dev, the development server starts up with

root@2731f07e003e:/app# npm run dev

> dev
> vite --host 0.0.0.0

  vite v2.9.12 dev server running at:

  > Local:    http://localhost:3000/
  > Network:  http://172.21.0.4:3000/

  ready in 506ms.

  Laravel v9.17.0 

  > APP_URL: http://localhost

But closes unexpectedly a second after running the command with no messages or error messages whatsoever.

I did some debugging and commented out process.exit(); in

const clean = () => {
    if (fs_1.default.existsSync(hotFile)) {
        fs_1.default.rmSync(hotFile);
    }
    process.exit();
};

and this finally made the dev server spit out the following error

root@2731f07e003e:/app# npm run dev

> dev
> vite --host 0.0.0.0

  vite v2.9.12 dev server running at:

  > Local:    http://localhost:3000/
  > Network:  http://172.21.0.4:3000/

  ready in 448ms.

  Laravel v9.17.0 

  > APP_URL: http://localhost
node:internal/errors:466
    ErrorCaptureStackTrace(err);
    ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/app/vendor/symfony/mailer/Transport/Smtp/Auth/XOAuth2Authenticator.php'
    at FSWatcher.<computed> (node:internal/fs/watchers:244:19)
    at Object.watch (node:fs:2306:34)
    at createFsWatchInstance (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:45512:17)
    at setFsWatchListener (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:45559:15)
    at NodeFsHandler$1._watchWithNodeFs (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:45714:14)
    at NodeFsHandler$1._handleFile (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:45778:23)
    at NodeFsHandler$1._addToNodeFs (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:46020:21)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:47208:10)
    at NodeFsHandler$1._addToNodeFs (/app/node_modules/vite/dist/node/chunks/dep-8f5c9290.js:46028:18) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/app/vendor/symfony/mailer/Transport/Smtp/Auth/XOAuth2Authenticator.php',
  filename: '/app/vendor/symfony/mailer/Transport/Smtp/Auth/XOAuth2Authenticator.php'
}

Node.js v18.3.0

A fix for users that use this package on Linux is running this command echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p It will automatically adjust the system watcher limit and make the changes live.

Steps To Reproduce:

I am using Ubuntu 20.04.4 server LTS x86_64 and Docker version 20.10.16, build aa7e414 with Docker compose v2

  1. Clone https://github.com/ericwang401/testing-laravel-vite
  2. Run docker compose up -d
  3. Enter into the workspace container docker compose exec workspace bash
  4. Install dependencies composer i && npm i
  5. Start the dev server npm run dev (make sure you went into node_modules and commented out process.exit in the Laravel Vite plugin cleanup function)
ericwang401 commented 2 years ago

I added a pull request to add documentation for this behavior in https://github.com/laravel/vite-plugin/pull/16

jessarcher commented 2 years ago

I'm not able to replicate this on Fedora 36 (and I don't have a custom sysctl.conf), but I have run into similar inotify issues in the past with Mix on large projects.

I'm wondering whether we can make this less silent so people have something to search for if it happens.

ericwang401 commented 2 years ago

I'm not able to replicate this on Fedora 36 (and I don't have a custom sysctl.conf), but I have run into similar inotify issues in the past with Mix on large projects.

I'm wondering whether we can make this less silent so people have something to search for if it happens.

Oh okay! Is there also a separate package for these directives to work?

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

I don't think Laravel is converting these directives to HTML when I went to the page with those directives. I'm also using Docker (in the repo), and I'm not sure if that conflicts as well.

jessarcher commented 2 years ago

Those are part of this framework PR https://github.com/laravel/framework/pull/42785 that we'll be merging and releasing soon.

You can test it out now by running composer require laravel/framework:"dev-vite as 9.11". You may need to php artisan view:clear if you've already tried to use the directives in your project.

The Vite integration isn't officially launched yet. We needed to publish the plugin early to test all the various starter kits and stacks.

jessarcher commented 2 years ago

Hi @ericwang401,

17 should improve the exit and signal handling so that uncaught exceptions (including your file watcher issue) are output to the console, while still cleaning the public/hot file.

I've verified this by using the command you mentioned above to set the watchers to 5 so that it always fails.

ericwang401 commented 2 years ago

Hi @ericwang401,

17 should improve the exit and signal handling so that uncaught exceptions (including your file watcher issue) are output to the console, while still cleaning the public/hot file.

I've verified this by using the command you mentioned above to set the watchers to 5 so that it always fails.

Hey, thank you for the update! I will create a new issue if a problem like this happens again in the future.

Thanks again!