Laravel Sail Stuck In npm: not found

Kumar Ravi
4 min readFeb 2, 2023

--

I don’t want to waste your time but this issue is so unique that it needs some of your time or you will remain stuck in this issue forever and no one will help you since It happens on very few people's computers.
If you don’t believe me here is an ongoing discussion about it.

If you want to save yourself from some trouble of figuring out and fixing this issue, here is a video on how to get Laravel Sail up and running in a newly installed Ubuntu 22.04 with Docker an Composer. I highly recommend you check this out.

So now that you are back and believe me I am going to take my time and after my solution, this issue will never happen again in any of your projects, It just vanishes in thin air.

First, tell me why the hell are you so unlucky or are you that daring that you decided to get the red pill? Yes, this issue is like taking that red pill and no one is gonna help you, wherever you will go for help they will say “Oh..but it is not happening in my system”

Anyways here is the solution

I have a fork of laravel sail so you will have to configure your project temporarily to use it, Yes temporarily, don’t worry, I got your back.
This is the fork: Here

Here is how to configure your composer to use my fork rather than laravel/sail official repository code.

Before that let's do some cleanup:

  1. clear your docker first so we have a clean slate to work with, follow these commands:
docker system df
docker system prune -f
docker system prune --volumes -f
docker builder prune --all -f
docker image prune -f
docker image prune -a -f
docker volume prune -f
docker network prune -f
docker builder prune -f

run these commands one by one

docker system df
shows you status of your docker containers images volums etc
keep running these command one by one till you see all values
se to 0 as output of docker system df

2. delete the docker-compose.yml your current sail has generated, or else you will keep scratching your head that what you did wrong, remember this is important. That’s why I am writing this in bold.

open your composer.json and just above require add this code.

"repositories": [
{
"type": "vcs",
"url": "https://github.com/kumarravisingh/sail.git"
}
]

one more change needed in our composer file is where you mention which branch to use.
so in your comopser.json file, there is a require-dev section here you need to add this:

"laravel/sail": "dev-first-time-sail-up-npm-install-issue-fix-in-ubuntu-22 as 1.19.0"

Important: My branch name is first-time-sail-up-npm-install-issue-fix-in-ubuntu-22 But I added dev- at the begining
so my complete version name here became :
dev-first-time-sail-up-npm-install-issue-fix-in-ubuntu-22

So if you are still confused here is what the composer.json file will look like.

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"repositories": [
{
"type":"vcs",
"url": "https://github.com/kumarravisingh/sail.git"
}
],
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "dev-first-time-sail-up-npm-install-issue-fix-in-ubuntu-22 as 1.19.0",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^5.10",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}

Now I am hoping you deleted your docker-compose.yml file from your project root folder, I am counting on you don’t forget to do that.

now the fun part

cd to your project root folder.
if you run “pwd” command it should show you the path to your project.

From here run this command

composer update

it will pull latest code from my fork on your project

php artisan sail:install

this will ask you to choose some options like this
[0] mysql
[1] pqsql
etc
enter 0 in your terminal and hit enter

your new docker-compose.yml file will get generated

now the main part:

Run this command now

vendor/bin/sail up -d

now wait till it starts It will take a little long to get up and running

If you have followed it correctly so far entering localhost in your browser should take it to your project
if still you are not able to see it
sometimes default nginx might be running
so run this command

sudo service nginx stop

This will stop ubuntu’s nginx and now
localhost in your browser will show you laravle project homepage

if it is asking you for a key generation then run the following command

php artisan key:generate

I should declare it here that part of my solution contains making an entry at the end of your .env file with these two values:

WWWGROUP=1000  
WWWUSER=1000

so if you see this don’t get confused, some users face issues if their docker is running as root user in ubuntu so this is a solution for that.

Now after your project is running you can remove my changes from your composer.json file and change your library name back to

"laravel/sail": "^1.0.1",

And from now on you will not face this issue again. This is the uniqueness of this issue, once gon it is gon forever.

I hope some way I was able to help you and have saved you some hours.

If yes then please consider buying me a coffee at my GitHub sponsor page: Kumar Ravi Github Sponsor Page

--

--