nodejs plugin: fix errors when building in confinement
Metadata
Current evaluation
Merged in #2747 (93fd28257), fixing confined Node.js builds with npm --unsafe-perm, no SUDO_UID, build-time installation, and no npm ls for Yarn.
Resolution: closed resolved
Reason: PR #2747 was merged and implemented the fix in commit 93fd28257, allowing npm lifecycle scripts to run under confined/root builds without dropping privileges.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh tests/unit`?
-----
This PR fixes errors when running the nodejs plugin with the base keyword.
I am now running `npm install` with `--unsafe-perm` and `SUDO_UID` unset. When building in a VM, node will crash upon running certain scripts because it drops the root UID when running them. It will sometimes ignore `--unsafe-perm` on certain commands, such as running `git` during a `npm install` that has a `git:` dependency, and the only way to override that is to drop `SUDO_UID`.
I am no longer running `npm install` during the pull step because:
1) It adds a significant amount of build time between the 'pull' and 'build' step, because it has to copy the project directory to the build directory and `node_modules` can be hundreds of thousands of files.
2) It is often the case that changes need to be made during the build process in between downloading node/npm/yarn and running `npm install`, such as importing private packages, setting custom a registry, etc. Without the ability to run `override-pull` before `npm install`, the pull step will crash.
I also skip running `npm ls` and populating the `manifest["node-packages"]` if yarn is used, because yarn often creates different dependency trees and it will crash the build if `npm ls` detects that the dependency graph (that npm would have generated) is missing dependencies.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged in #2747 (93fd28257), fixing confined Node.js builds with npm --unsafe-perm, no SUDO_UID, build-time installation, and no npm ls for Yarn. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged as commit 93fd28257 "nodejs plugin: fix errors when building with sudo (#2747)". Runs npm install with --unsafe-perm and SUDO_UID unset, moves install to the build step, and skips npm ls for yarn. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged in canonical/snapcraft#2747 (commit 93fd28257): npm uses --unsafe-perm without SUDO_UID, installs during build, and skips npm ls for yarn. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged in #2747 (commit 93fd28257), fixing confined nodejs builds by using npm --unsafe-perm with SUDO_UID unset, moving npm install to build, and skipping npm ls for yarn. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged fix for nodejs plugin confinement build errors. Unsets SUDO_UID, applies --unsafe-perm to npm install, moves installation out of the pull step, and skips npm ls for yarn. Approved and merged. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged nodejs plugin fix for confinement build failures. npm install uses --unsafe-perm and unsets SUDO_UID to prevent crashes. Pull step no longer runs npm install, saving time. npm ls is skipped with yarn to avoid errors. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1023 nodejs plugin: fix the plugin’s dependency installation | snapcraft | merged | Merged PR #1023 as commit d3b476573, fixing the Node.js plugin’s dependency installation for LP #1652542. | |
| #490 nodejs plugin: Allow building N times | snapcraft | merged | Merged PR #490 in commit a25b083da, preserving the npm download so the Node.js plugin can build repeatedly and resolve LP #1575882. |