Impossible to build Eleventy as SSH command

My YunoHost server

Hardware: VPS bought online
YunoHost version: 11.0.10.2
I have access to my server : Through SSH + through the webadmin
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Description of my issue

Original post in Eleventy discussions on GitHub.

I have a copy of my Eleventy website installed on a Debian 11 VPS, which I access via SSH.

The repository of my website lies in the home directory of the administration user.

The script I run to build the website is npm run build and you can see what this command triggers by looking at my package.json file.

I will skip all the other unnecessary details and get straight to the error.

When I SSH into the server directly, then cd into the website repo and run npm run build, the website is deployed with no problems at all. Nevertheless, if I pass only the command via SSH (ssh -p 302323 admin@test.server.tld 'cd tommi.space && npm run build'), I get this error instead:

> tommi.space@1.0.0 build
> npm-run-all build:*


> tommi.space@1.0.0 build:sass
> sass --style=compressed styles/:www


> tommi.space@1.0.0 build:eleventy
> ELEVENTY_ENV=production eleventy

[11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
[11ty] 1. Error in your Eleventy config file '/home/admin/tommi.space/.eleventy.js'. (via EleventyConfigError)
[11ty] 2. Unexpected token '.' (via SyntaxError)
[11ty]
[11ty] Original error stack trace: /home/admin/tommi.space/node_modules/linkedom/cjs/html/option-element.js:23
[11ty]     const option = this.parentElement?.querySelector('option[selected]');
[11ty]                                       ^
[11ty]
[11ty] SyntaxError: Unexpected token '.'
[11ty]     at wrapSafe (internal/modules/cjs/loader.js:915:16)
[11ty]     at Module._compile (internal/modules/cjs/loader.js:963:27)
[11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
[11ty]     at Module.load (internal/modules/cjs/loader.js:863:32)
[11ty]     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
[11ty]     at Module.require (internal/modules/cjs/loader.js:887:19)
[11ty]     at require (internal/modules/cjs/helpers.js:74:18)
[11ty]     at Object.<anonymous> (/home/admin/tommi.space/node_modules/linkedom/cjs/shared/html-classes.js:32:29)
[11ty]     at Module._compile (internal/modules/cjs/loader.js:999:30)
[11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
npm ERR! code 1
npm ERR! path /home/admin/tommi.space
npm ERR! command failed
npm ERR! command sh -c ELEVENTY_ENV=production eleventy

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/admin/.npm/_logs/2022-11-30T16_21_38_837Z-debug.log
ERROR: "build:eleventy" exited with 1.
npm ERR! code 1
npm ERR! path /home/admin/tommi.space
npm ERR! command failed
npm ERR! command sh -c npm-run-all build:*

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/admin/.npm/_logs/2022-11-30T16_21_38_865Z-debug.log

Below the content of the /home/admin/.npm/_logs/2022-11-30T16_21_38_837Z-debug.log file:

0 verbose cli [
0 verbose cli   '/usr/bin/node',
0 verbose cli   '/usr/share/nodejs/npm/bin/npm-cli.js',
0 verbose cli   'run',
0 verbose cli   'build:eleventy'
0 verbose cli ]
1 info using npm@7.5.2
2 info using node@v12.22.12
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/home/admin/tommi.space/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/home/admin/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 8ms
19 verbose npm-session 2eb536f44bd264ce
20 timing npm:load Completed in 17ms
21 timing command:run-script Completed in 1005ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (/usr/share/nodejs/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack     at ChildProcess.emit (events.js:314:20)
22 verbose stack     at maybeClose (internal/child_process.js:1022:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
23 verbose pkgid tommi.space@1.0.0
24 verbose cwd /home/admin/tommi.space
25 verbose Linux 5.10.0-19-amd64
26 verbose argv "/usr/bin/node" "/usr/share/nodejs/npm/bin/npm-cli.js" "run" "build:eleventy"
27 verbose node v12.22.12
28 verbose npm  v7.5.2
29 error code 1
30 error path /home/admin/tommi.space
31 error command failed
32 error command sh -c ELEVENTY_ENV=production eleventy
33 verbose exit 1

…and of /home/admin/.npm/_logs/2022-11-30T16_21_38_865Z-debug.log:

0 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build' ]
1 info using npm@7.5.2
2 info using node@v12.22.12
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/usr/share/nodejs/npm/npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 2ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:/home/admin/tommi.space/.npmrc Completed in 0ms
9 timing config:load:project Completed in 4ms
10 timing config:load:file:/home/admin/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/etc/npmrc Completed in 1ms
13 timing config:load:global Completed in 1ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 14ms
19 verbose npm-session 93f6a571b16be009
20 timing npm:load Completed in 25ms
21 timing command:run-script Completed in 2912ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (/usr/share/nodejs/@npmcli/promise-spawn/index.js:64:27)
22 verbose stack     at ChildProcess.emit (events.js:314:20)
22 verbose stack     at maybeClose (internal/child_process.js:1022:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
23 verbose pkgid tommi.space@1.0.0
24 verbose cwd /home/admin/tommi.space
25 verbose Linux 5.10.0-19-amd64
26 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
27 verbose node v12.22.12
28 verbose npm  v7.5.2
29 error code 1
30 error path /home/admin/tommi.space
31 error command failed
32 error command sh -c npm-run-all build:*
33 verbose exit 1

Apparently this is a syntax issue in your .eleventy.js conf file

I see that, but the problem is that there is not! If I run the build script from within the SSH, it works perfectly.

My take is that there are some JS dependencies that are not correctly loaded by running the build script as SSH command, and therefore the config file is not interpreted correctly.

My question is: why does this happen? How could I fix it?

Can you check the output of echo $PATH with the two ways you have tried to execute the commands? (SSH prompt vs command sent via SSH)

Sure.

This is the output of echo $PATH from SSH prompt:

/home/admin/.rvm/gems/ruby-3.0.0/bin:/home/admin/.rvm/gems/ruby-3.0.0@global/bin:/home/admin/.rvm/rubies/ruby-3.0.0/bin:/home/admin/.local/bin:/home/admin/.nvm/versions/node/v18.12.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/admin/.rvm/bin

And this is the output of ssh -p 34571390485719 admin@server.tld 'echo $PATH':

/usr/local/bin:/usr/bin:/bin:/usr/games

What does this difference mean?

It could mean the Node environment is not loaded when you directly call the commands from ssh.
Try:

ssh -p ???? admin@test.server.tld 'cd tommi.space && PATH=/home/admin/.rvm/gems/ruby-3.0.0/bin:/home/admin/.rvm/gems/ruby-3.0.0@global/bin:/home/admin/.rvm/rubies/ruby-3.0.0/bin:/home/admin/.local/bin:/home/admin/.nvm/versions/node/v18.12.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/admin/.rvm/bin npm run build'
1 Like

That was it. Thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.