Closed dilyn-corner closed 1 month ago
That's interesting. I'm not familiar enough with Node or JS to explain how that's the case.
For instance, there are a lot of these types of messages when building:
:: npm WARN notsup Unsupported engine for express-fileupload@1.5.1: wanted: {"node":">=12.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: express-fileupload@1.5.1
:: npm WARN notsup Unsupported engine for tmp@0.2.3: wanted: {"node":">=14.14"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: tmp@0.2.3
:: npm WARN notsup Unsupported engine for web-push@3.6.7: wanted: {"node":">= 16"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: web-push@3.6.7
:: npm WARN notsup Unsupported engine for winston@3.15.0: wanted: {"node":">= 12.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: winston@3.15.0
:: npm WARN notsup Unsupported engine for npmlog@6.0.2: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: npmlog@6.0.2
:: npm WARN notsup Unsupported engine for ip-address@9.0.5: wanted: {"node":">= 12"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: ip-address@9.0.5
:: npm WARN notsup Unsupported engine for are-we-there-yet@3.0.1: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: are-we-there-yet@3.0.1
:: npm WARN notsup Unsupported engine for gauge@4.0.4: wanted: {"node":"^12.13.0 || ^14.15.0 || >=16.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: gauge@4.0.4
:: npm WARN notsup Unsupported engine for https-proxy-agent@7.0.5: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: https-proxy-agent@7.0.5
:: npm WARN notsup Unsupported engine for http_ece@1.2.0: wanted: {"node":">=16"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: http_ece@1.2.0
:: npm WARN notsup Unsupported engine for agent-base@7.1.1: wanted: {"node":">= 14"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: agent-base@7.1.1
:: npm WARN notsup Unsupported engine for triple-beam@1.4.1: wanted: {"node":">= 14.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: triple-beam@1.4.1
:: npm WARN notsup Unsupported engine for winston-transport@4.8.0: wanted: {"node":">= 12.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: winston-transport@4.8.0
:: npm WARN notsup Unsupported engine for logform@2.6.1: wanted: {"node":">= 12.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: logform@2.6.1
:: npm WARN notsup Unsupported engine for readable-stream@4.5.2: wanted: {"node":"^12.22.0 || ^14.17.0 || >=16.0.0"} (current: {"node":"10.24.1","npm":"6.14.12"})
:: npm WARN notsup Not compatible with your version of node/npm: readable-stream@4.5.2
BTW these patches would be more useful as pull requests if you're able to create them.
Done! 🫡
Thank you very much for these patches.
Might there be a reason that local builds of the snap with Node.js 10 were working fine, but remote builds on snapcraft.io are somehow different?
They shouldn't be different. How are you building the snap locally?
I'm just running snapcraft
on Ubuntu Desktop from a clone of the git repo, and sometimes snapcraft clean && snapcraft
. Current version is snapcraft 8.4.2.
I'm building with snapcraft 8.x (various versions) with
--use-lxd
, I'm trying now with snapcraft 7.5.5 in a Jammy container with--destructive-mode
to compare.(Just ran a build in a Jammy LXD container using snapcraft 7.5.5 with
snapcraft --destructive-mode
and installed the snap with--dangerous
, I get the same error message of2024-10-08T21:39:41Z webthings-gateway.webthings-gateway[4792]: ReferenceError: globalThis is not defined
).The build environment shouldn't really impact this, as this is a runtime problem; indeed, this problem should have always existed, as snapcraft will always fetch the node version you specify (as part of the npm plugin).
Curiously I've not seen this error. If you want to examine a successfully built snap using Node.js 10.24.1 as per the initial snapcraft.yaml provided by @ogra1 you can install it using $ snap install webthings-gateway --revision 1
(on an AMD64 machine). I built that snap locally and uploaded it to the snap store because automated builds were broken.
Apart from this I run WebThings Gateway locally with Node.js 10 all the time in development and that's what the current stable 1.1 release is using, so it should run fine.
I'm assuming this is intended to fix an error which I also #3167 (comment) with local builds of the snap.
Indeed it is!
In that case I found that when I started from a fresh git checkout the error went away.
Does this mean that you are building with
--destructive-mode
?
No I mean I literally created a new local clone of the GitHub repo and ran snapcraft
and the error went away.
Whilst I am OK with the proposed fix, I would prefer to understand the cause of this error. It could be something as simple as the build directory already existing.
The real reason the failure happens is if you build, don't clean, and attempt a rebuild; the file already exists in the target location, and for some reason snapcraft is rerunning the build step for that part again. But
cp
will refuse to overwrite the same file, and returns withexit 1
; because of that nonzero exit code, snapcraft considers a step to have failed and stops the build.In this specific instance, overwriting is safe. Generally speaking, overwriting is usually the behavior you would want (for instance, many
Makefile
s will usecp -f
,rm -f
,ln -f
, etc.).
Hmm, OK.
For instance, there are a lot of these types of messages when building:
Yes these are just warnings and this is normal. The upgrade to Node.js 20 should eventually get rid of all these warnings.
With the patches in this PR I have successfully been able to locally build the snap and can confirm that it runs.
I can also confirm that without the commit which bumps the Node.js version the snap fails to start.
$ sudo journalctl -fu snap.webthings-gateway.webthings-gateway.service
Oct 09 20:10:15 frell webthings-gateway.webthings-gateway[82082]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Oct 09 20:10:15 frell webthings-gateway.webthings-gateway[82082]: npm ERR! A complete log of this run can be found in:
Oct 09 20:10:15 frell webthings-gateway.webthings-gateway[82082]: npm ERR! /root/snap/webthings-gateway/x2/.npm/_logs/2024-10-09T19_10_15_457Z-debug.log
Oct 09 20:10:15 frell systemd[1]: snap.webthings-gateway.webthings-gateway.service: Main process exited, code=exited, status=1/FAILURE
Oct 09 20:10:15 frell systemd[1]: snap.webthings-gateway.webthings-gateway.service: Failed with result 'exit-code'.
Oct 09 20:10:15 frell systemd[1]: snap.webthings-gateway.webthings-gateway.service: Scheduled restart job, restart counter is at 5.
Oct 09 20:10:15 frell systemd[1]: Stopped Service for snap application webthings-gateway.webthings-gateway.
Oct 09 20:10:15 frell systemd[1]: snap.webthings-gateway.webthings-gateway.service: Start request repeated too quickly.
Oct 09 20:10:15 frell systemd[1]: snap.webthings-gateway.webthings-gateway.service: Failed with result 'exit-code'.
Oct 09 20:10:15 frell systemd[1]: Failed to start Service for snap application webthings-gateway.webthings-gateway.
$ snap logs -f webthings-gateway
2024-10-09T20:10:15+01:00 webthings-gateway.webthings-gateway[82082]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2024-10-09T20:10:15+01:00 webthings-gateway.webthings-gateway[82082]: npm ERR! A complete log of this run can be found in:
2024-10-09T20:10:15+01:00 webthings-gateway.webthings-gateway[82082]: npm ERR! /root/snap/webthings-gateway/x2/.npm/_logs/2024-10-09T19_10_15_457Z-debug.log
2024-10-09T20:10:15+01:00 systemd[1]: snap.webthings-gateway.webthings-gateway.service: Main process exited, code=exited, status=1/FAILURE
2024-10-09T20:10:15+01:00 systemd[1]: snap.webthings-gateway.webthings-gateway.service: Failed with result 'exit-code'.
2024-10-09T20:10:15+01:00 systemd[1]: snap.webthings-gateway.webthings-gateway.service: Scheduled restart job, restart counter is at 5.
2024-10-09T20:10:15+01:00 systemd[1]: Stopped Service for snap application webthings-gateway.webthings-gateway.
2024-10-09T20:10:15+01:00 systemd[1]: snap.webthings-gateway.webthings-gateway.service: Start request repeated too quickly.
2024-10-09T20:10:15+01:00 systemd[1]: snap.webthings-gateway.webthings-gateway.service: Failed with result 'exit-code'.
2024-10-09T20:10:15+01:00 systemd[1]: Failed to start Service for snap application webthings-gateway.webthings-gateway.
$ sudo less /root/snap/webthings-gateway/x2/.npm/_logs/2024-10-09T19_10_15_457Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/snap/webthings-gateway/x2/bin/node',
1 verbose cli '/snap/webthings-gateway/x2/bin/npm',
1 verbose cli '--prefix',
1 verbose cli '/snap/webthings-gateway/x2/lib/node_modules/webthings-gateway',
1 verbose cli 'run',
1 verbose cli 'run-only' ]
2 info using npm@6.14.12
3 info using node@v10.24.1
4 verbose run-script [ 'prerun-only', 'run-only', 'postrun-only' ]
5 info lifecycle webthings-gateway@1.2.0-alpha.1~prerun-only: webthings-gateway@1.2.0-alpha.1
6 info lifecycle webthings-gateway@1.2.0-alpha.1~run-only: webthings-gateway@1.2.0-alpha.1
7 verbose lifecycle webthings-gateway@1.2.0-alpha.1~run-only: unsafe-perm in lifecycle true
8 verbose lifecycle webthings-gateway@1.2.0-alpha.1~run-only: PATH: /snap/webthings-gateway/x2/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/snap/webthings-gateway/x2/lib/node_modules/webthings-gateway/node_modules/.bin:/snap/webthings-gateway/x2/lib/node_modules/.bin:/snap/webthings-gateway/x2/usr/sbin:/snap/webthings-gateway/x2/usr/bin:/snap/webthings-gateway/x2/sbin:/snap/webthings-gateway/x2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 verbose lifecycle webthings-gateway@1.2.0-alpha.1~run-only: CWD: /snap/webthings-gateway/x2/lib/node_modules/webthings-gateway
10 silly lifecycle webthings-gateway@1.2.0-alpha.1~run-only: Args: [ '-c', 'node build/app.js' ]
11 silly lifecycle webthings-gateway@1.2.0-alpha.1~run-only: Returned: code: 1 signal: null
12 info lifecycle webthings-gateway@1.2.0-alpha.1~run-only: Failed to exec run-only script
13 verbose stack Error: webthings-gateway@1.2.0-alpha.1 run-only: `node build/app.js`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/snap/webthings-gateway/x2/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (/snap/webthings-gateway/x2/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid webthings-gateway@1.2.0-alpha.1
15 verbose cwd /var/snap/webthings-gateway/x2
16 verbose Linux 6.8.0-45-generic
17 verbose argv "/snap/webthings-gateway/x2/bin/node" "/snap/webthings-gateway/x2/bin/npm" "--prefix" "/snap/webthings-gateway/x2/lib/node_modules/webthings-gateway" "run" "run-only"
18 verbose node v10.24.1
19 verbose npm v6.14.12
20 error code ELIFECYCLE
21 error errno 1
22 error webthings-gateway@1.2.0-alpha.1 run-only: `node build/app.js`
22 error Exit status 1
23 error Failed at the webthings-gateway@1.2.0-alpha.1 run-only script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
/root/snap/webthings-gateway/x2/.npm/_logs/2024-10-09T19_10_15_457Z-debug.log (END)
In which log did you find the error ReferenceError: globalThis is not defined
? I haven't been able to find it and I would like to better understand what's going on.
In the meantime I'm going to land these patches because they do seem to fix the snap and I don't particularly mind upgrading the snap to Node.js 12 given I'm trying to upgrade to Node.js 20 anyway. However, that does diverge from the main build target of current master and I find it disconcerting that a snapcraft.yaml which was previously working for both me and @ogra1 has suddenly stopped working.
Let's see if landing this PR gets the remote builds working on other platforms.
Thanks
In which log did you find the error ReferenceError: globalThis is not defined
I saw this printed to stdout after doing the following:
sudo snap run --shell webthings-gateway
NPM_CONFIG_LOGLEVEL=verbose npm --prefix $SNAP/lib/node_modules/webthings-gateway/ run run-only
I had the idea to increase the verbosity simply because the messages being given weren't actually meaningful errors, rather just indicating that there is an error. E.g.,
20 error code ELIFECYCLE
21 error errno 1
22 error webthings-gateway@1.2.0-alpha.1 run-only: `node build/app.js`
22 error Exit status 1
23 error Failed at the webthings-gateway@1.2.0-alpha.1 run-only script.
Isn't actually a meaningful message in my experience; I would expect some additional message in the 22 lines.
However, that does diverge from the main build target of current master and I find it disconcerting that a snapcraft.yaml which was previously working for both me and @ogra1 has suddenly stopped working.
The only hunch I had as to why you weren't seeing this issue is somehow a different Node had gotten injected into the snap somehow, hence my questions about destructive mode (Node from host somehow finding its way into $CRAFT_PART_INSTALL
could muddy the waters, as it were). But considering you're just doing snapcraft
and presumably don't have SNAPCRAFT_BUILD_ENVIRONMENT=host
set... that becomes less convincing a rationale.
I do agree that this is disconcerting and I will try to reach out to the snapcraft folx to see if they have any ideas for what could be happening. I can't think of any changes which would have happened in the last few months which would impact this, though.
I discussed with the team and they think it may have had something to do with this change, as it aligns with your experience time-wise and what you were previously doing (and potentially explains the most recent slew of snapcraft.io/build failures).
Done! 🫡
Closes #3171 Closes #3167
That's interesting. I'm not familiar enough with Node or JS to explain how that's the case.
They shouldn't be different. How are you building the snap locally? I'm building with snapcraft 8.x (various versions) with
--use-lxd
, I'm trying now with snapcraft 7.5.5 in a Jammy container with--destructive-mode
to compare.(Just ran a build in a Jammy LXD container using snapcraft 7.5.5 with
snapcraft --destructive-mode
and installed the snap with--dangerous
, I get the same error message of2024-10-08T21:39:41Z webthings-gateway.webthings-gateway[4792]: ReferenceError: globalThis is not defined
).The build environment shouldn't really impact this, as this is a runtime problem; indeed, this problem should have always existed, as snapcraft will always fetch the node version you specify (as part of the npm plugin).
Indeed it is!
Does this mean that you are building with
--destructive-mode
?The real reason the failure happens is if you build, don't clean, and attempt a rebuild; the file already exists in the target location, and for some reason snapcraft is rerunning the build step for that part again. But
cp
will refuse to overwrite the same file, and returns withexit 1
; because of that nonzero exit code, snapcraft considers a step to have failed and stops the build.In this specific instance, overwriting is safe. Generally speaking, overwriting is usually the behavior you would want (for instance, many
Makefile
s will usecp -f
,rm -f
,ln -f
, etc.).