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

kenyonkowal's avatar

"Deploy Now" fails but SSH works

I have a problem where the auto-deployment fails but if I SSH into the server and run the exact npm command, it runs fine.

Any ideas?

0 likes
12 replies
bugsysha's avatar

Without specific details from deployment log it is hard to say anything. Are you running it as same user and are you sure that you've matched everything?

kenyonkowal's avatar

@bugsysha Yep, running the exact same command. I even removed everything from the build script to just npm i && npm run build and it still fails, but when I ssh in and run the command it builds fine.

kenyonkowal's avatar

Here the npm log when it fails when running "Deploy Now" through the admin panel.

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/forge/project.domain.io/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 verbose lifecycle [email protected]~build: CWD: /home/forge/project.domain.io
10 silly lifecycle [email protected]~build: Args: [ '-c',
10 silly lifecycle   'npm run tailwind && NODE_ENV=prod webpack -p --config ./webpack/prod.js --hide-modules' ]
11 silly lifecycle [email protected]~build: Returned: code: 137  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `npm run tailwind && NODE_ENV=prod webpack -p --config ./webpack/prod.js --hide-modules`
13 verbose stack Exit status 137
13 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/forge/project.domain.io
16 verbose Linux 4.15.0-112-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
18 verbose node v8.11.3
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 137
22 error [email protected] build: `npm run tailwind && NODE_ENV=prod webpack -p --config ./webpack/prod.js --hide-modules`
22 error Exit status 137
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 137, true ]
bugsysha's avatar

Have you tried using npm ci instead of npm i?

1 like
kenyonkowal's avatar

@bugsysha I think this is an issue with node/npm versions.

It looks like when I'm SSH'd in it uses

node -v = v12.18.3
npm -v = 6.14.6

But Auto deploy uses:

sudo node -v = v8.11.3
sudo npm -v = 5.6.0

I'm guessing this is what the problem is. When auto-deployment runs, it uses the sudo version (npm v5, node v8)

kenyonkowal's avatar

I figure this out because npm ci says it couldn't be found in the deploy script, which means the npm version was too low. When using the non-sudo version (v12) through SSH npm ci works

Should I update node/npm for sudo? How would I do that?

bugsysha's avatar

But you said that you were using the same user? If you are using sudo then it is not same command in both scenarios. I would avoid using sudo in my scripts.

kenyonkowal's avatar

@bugsysha maybe something got missed. I am not using sudo.

If I add npm -v to the auto-deploy script it outputs 5.6.0, so by default auto-deployment is using sudo I am guessing. There is no way to change that in the deploy script.

if I SSH into the server and run npm -v i get 6.14.6

bugsysha's avatar

Who wrote the script. It is probably logging in with the sudo user or executing something. If you are sure that you will not break anything then just update sudo version of npm.

kenyonkowal's avatar

@bugsysha This is the default with the forge. At no point does it sudo.

This is the full script

cd /home/forge/domain.com
git fetch --all && git reset --hard origin/develop && git pull origin develop

npm i && npm run build

composer install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service php7.3-fpm reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    php artisan migrate --force
fi
kenyonkowal's avatar
kenyonkowal
OP
Best Answer
Level 1

ssh'ing in an updating sudo node/npm version fixed it.

Just used the same as the ssh version is using, so they are consistent sudo n 12.18.3

But seems weird that there would be two versions in the first place.

bugsysha's avatar

LOL, at no point did I figure out that you were talking about Forge :facepalm:

Please or to participate in this conversation.