Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sturm's avatar
Level 5

Cannot run NPM Install, Composer Install, nor even commit

Everything is falling apart on my local dev machine and I don't have a clue why. It was running fine last week, after I had formatted my PC to start from scratch. I do my development in WSL and have been doing so for years. No problems until now.

Now, when I tried to commit a simple change to a new branch, husky complains:

08:41:03.286: [nexus] /usr/bin/git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- resources/js/Pages/Loads/Show.vue resources/js/Pages/Loads/partials/LoadCardPhaseProgress.vue
08:41:03.348: [nexus] /usr/bin/git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F /mnt/c/Users/kerban/AppData/Local/Temp/git-commit-msg-.txt --
time="2024-06-25T08:41:03-04:00" level=warning msg="/home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete"
time="2024-06-25T08:41:03-04:00" level=warning msg="/home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete"
> pre-commit
> lint-staged
✖ Current directory is not a git directory!
husky - pre-commit hook exited with code 1 (error)

As a part of my usual troubleshooting steps, I attempt to ensure that all my dependencies are up to date, but both of those fail.

sail npm install:

WARN[0000] /home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete
WARN[0000] /home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete
npm error code EACCES
npm error syscall rename
npm error path /tmp/ab542c8e-0317-4b88-b9c3-9039edb3f630/node_modules/electron-to-chromium
npm error dest /tmp/ab542c8e-0317-4b88-b9c3-9039edb3f630/node_modules/.electron-to-chromium-TaB3HUTg
npm error errno -13
npm error Error: EACCES: permission denied, rename '/tmp/***/node_modules/electron-to-chromium' -> '/tmp/***/node_modules/.electron-to-chromium-TaB3HUTg'
npm error     at async Object.rename (node:internal/fs/promises:779:10)
npm error     at async moveFile (/usr/lib/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js:30:5)
npm error     at async Promise.allSettled (index 0)
npm error     at async [reifyPackages] (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:325:11)
npm error     at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:142:5)
npm error     at async Install.exec (/usr/lib/node_modules/npm/lib/commands/install.js:150:5)
npm error     at async Npm.exec (/usr/lib/node_modules/npm/lib/npm.js:207:9)
npm error     at async module.exports (/usr/lib/node_modules/npm/lib/cli/entry.js:74:5) {
npm error   errno: -13,
npm error   code: 'EACCES',
npm error   syscall: 'rename',
npm error   path: '/tmp/ab542c8e-0317-4b88-b9c3-9039edb3f630/node_modules/electron-to-chromium',
npm error   dest: '/tmp/ab542c8e-0317-4b88-b9c3-9039edb3f630/node_modules/.electron-to-chromium-TaB3HUTg'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error A complete log of this run can be found in: /home/sail/.npm/_logs/2024-06-25T12_44_52_487Z-debug-0.log

sail composer install:

WARN[0000] /home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete
WARN[0000] /home/sturm/dev/xxxxxxx/xxxxx/docker-compose.yml: `version` is obsolete
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove

In Filesystem.php line 895:

  file_put_contents(/tmp/ab542c8e-0317-4b88-b9c3-9039edb3f630/vendor/composer/installed.php): Failed t
  o open stream: Permission denied


install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--download-only] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [--audit] [--audit-format AUDIT-FORMAT] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]

What on earth is going on?

To give some extra context in case it helps, there are two unusual things I do that most people don't when setting up the local clone of the repo.

For one, I have both a personal and work GitHub account, so I have named them as such in my ~/.ssh/config file.

#personal account
Host github.com-personal
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ed25519

#iel account
Host github.com-iel
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ed25519_iel

So when I initially cloned the repo, I had to alter the line slightly.

git clone [email protected]:xxxxxxx/xxxxx.git

However, subsequent git pulls have had no problems, so the remote origin is set up fine.

The second thing is that I have a shell script (which still needs some work, admittedly) to clone the repo and set it up locally. I've tried to make it so that any developer at my company can use it.

# Ensure that Docker is running...
if ! docker info > /dev/null 2>&1; then
    echo "Docker is not running."
    exit 1
fi

if ! git clone [email protected]:xxxxxxx/xxxxx.git; then
    echo "Could not clone the repository. Please check your SSH keys and ensure the 'nexus' directory does not exist."
    exit 1
fi

cd xxxxx || exit

if [ ! -f ".env" ]; then
    cp .env.example .env
    sed -i 's/nexus\.lndo\.site/localhost/g' .env
fi

docker run --rm \
    --pull=always \
    -v "$(pwd)":/opt \
    -w /opt \
    -u $(id -u):$(id -g) \
    laravelsail/php83-composer:latest \
    bash -c "composer install --ignore-platform-reqs"

./vendor/bin/sail build
./vendor/bin/sail up -d
sleep 1
./vendor/bin/sail up -d database
./vendor/bin/sail artisan migrate --seed
./vendor/bin/sail artisan telescope:publish

BOLD='3[1m'
NC='3[0m'

echo ""

if sudo -n true 2>/dev/null; then
    sudo chown -R "$USER": .
    echo -e "${BOLD}Congratulations! Xxxxx is almost finished installing.${NC} Please finish by following steps 3–6 at https://github.com/xxxxxxx/xxxxx/wiki/Installing-with-Sail#fresh-install"
else
    echo -e "${BOLD}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
    echo ""
    sudo chown -R "$USER": .
    echo ""
    echo -e "${BOLD}Congratulations! Nexus is almost finished installing.${NC} Please finish by following steps 3–6 at https://github.com/xxxxxxx/xxxxx/wiki/Installing-with-Sail#fresh-install"
fi

It was originally adapted from Laravel's own installation script from Laravel 10, so I don't know if they've made some breaking changes since then. I recently added the -u $(id -u):$(id -g) \ to the Docker Composer installation command.

Because I have an odd SSH Config setup, I don't use the script as is, I just copy/paste each command and run them separately, modifying the initial git clone, of course.

So, there's my situation. I cannot sail npm i nor sail composer i anymore, nor can I even make a simple commit, because husky thinks it's not a Git repo. I don't know what to do now.

0 likes
9 replies
LaryAI's avatar
Level 58

It looks like you're encountering multiple issues related to permissions and possibly some misconfigurations. Let's address them step by step.

1. Husky Pre-commit Hook Issue

The error message Current directory is not a git directory! suggests that Husky is not recognizing your repository as a Git repository. This could be due to a misconfiguration in your Husky setup or an issue with your Git configuration.

Solution:

  1. Check Husky Configuration: Ensure that Husky is properly configured in your project. You should have a .husky directory with the necessary hooks.
  2. Reinstall Husky:
    npx husky install
    

2. NPM Install Permission Issue

The EACCES: permission denied error indicates that there are permission issues when NPM tries to rename files in the /tmp directory.

Solution:

  1. Clear NPM Cache:
    npm cache clean --force
    
  2. Change NPM's Default Directory:
    mkdir ~/.npm-global
    npm config set prefix '~/.npm-global'
    export PATH=~/.npm-global/bin:$PATH
    source ~/.profile
    
  3. Run NPM Install Again:
    sail npm install
    

3. Composer Install Permission Issue

The Permission denied error when running composer install suggests that there are permission issues with the /tmp directory.

Solution:

  1. Clear Composer Cache:
    composer clear-cache
    
  2. Run Composer with Elevated Permissions:
    sail composer install --ignore-platform-reqs
    

4. Docker Compose Version Warning

The warning about the version field being obsolete in your docker-compose.yml file suggests that you might be using an outdated version of Docker Compose.

Solution:

  1. Update Docker Compose:
    sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    

5. General Troubleshooting Steps

  1. Check Docker Status: Ensure Docker is running:
    docker info
    
  2. Check File Permissions: Ensure you have the correct permissions for the project directory:
    sudo chown -R $USER:$USER /path/to/your/project
    

Summary

By addressing the issues step by step, you should be able to resolve the permission errors and configuration issues. If the problems persist, consider creating a new WSL instance or a fresh Docker environment to rule out any environment-specific issues.

If you need further assistance, feel free to ask!

Sturm's avatar
Level 5

This could be due to a misconfiguration in your Husky setup or an issue with your Git configuration.

I agree that there may be something wrong with my Git configuration, but I have no clue what. For example, even on my PowerLevel10k command line, I am seeing something unusual. Here is how my prompt looks now:

https://i.imgur.com/GPyo3FM.png

The "git" area I highlighted is normally replaced with the Octocat icon when it is correctly connected to a GitHub repo. So I feel like something is definitely amiss here, but I don't know what.

I also don't see how that would have any effect on sail npm i and sail composer i.

martinbean's avatar

@sturm Did you read the last line before the exit? It’s saying the directory you’re running it in isn’t a Git-tracked directory.

Sturm's avatar
Level 5

@martinbean Oh, I know it says that. I've been Googling that, I've asked my colleagues about that, and I have yet to understand why husky thinks it isn't git-tracked, when it most definitely is.

Or, at least, it should be. There's a .git directory with everything in it that should be there AFAIK, git pull works fine, so origin is also set up correctly.

I wish husky would give me more detail as to why it believes that it isn't git-tracked.

Sturm's avatar
Level 5

I've just discovered part of the problem.

https://i.imgur.com/w0cbl0B.png

There's an additional Docker container being created that isn't in the docker-compose.yml file. After I delete the container, I can run sail composer i and sail npm i.

However, this container keeps recreating itself every time I delete it from Docker Desktop. It's named similar to the correct container, laravel.test-1, but has 'run' and a hash in its name: laravel.test-run-ace67bff3aee

What is causing this rogue container to keep recreating itself and how do I stop it?

UPDATE: I know what's causing it: PhpStorm. But I still don't know why.

martinbean's avatar

@Sturm Well is the issue not that, you’re trying to run commands via Sail, but you’ve not actually created your Sail environment?

You can’t run sail commands until you’ve actually ran sail build to create the Docker images you wish to run Sail commands in.

Sturm's avatar
Level 5

@martinbean Nope. All of the Sail containers have been started and are running fine. It has nothing to do with sail build since I already ran that command shortly after cloning the repo.

The issue is that PhpStorm is creating this rogue "sail" container that is interfering with the proper ones. When I delete that rogue container, I can run my Sail command perfectly. The problem is that PhpStorm re-creates the container within a few seconds, so I don't have much time to run my Sail commands.

The strange thing is that this wasn't an issue before the last few days. I cannot think of a single thing that has changed since then.

I am going to contact JetBrains about this issue and pray that they have some sort of solution.

martinbean's avatar

@Sturm They’ve not been built, though. If they had, then they’d be a Compose project with various images.

Here’s a screenshot of my Docker Desktop, where I have two projects ran via Sail: vod and cms. It shows the top-level Compose project names, which can then be expanded to show the actual images used in that Compose project. Your screenshot showed no such project.

Sturm's avatar
Level 5

@martinbean Ah, I see your confusion. That screenshot was taken after I deleted the Sail containers to help me identify the cause of this rogue container. Here's a screenshot I just took where the regular Sail containers are running and I just started up PhpStorm, and here is a screen recording of it in action.

Please or to participate in this conversation.