nodejs plugin: fix errors when building in confinement
Metadata
Current evaluation
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.
Suggested action: —
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 |
|---|---|---|---|---|
| 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. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged nodejs plugin fix for confinement build crashes. Passes --unsafe-perm and unsets SUDO_UID during npm install, defers installation to the build step for overrides and speed, and skips npm ls when using yarn. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #800 LP: #1623509 nodejs: fix to install dev-deps in build phase | snapcraft | merged | Merged a fix for the nodejs plugin to install devDependencies during the build phase. Approved by a reviewer after confirming unrelated CI failures, the change was successfully integrated. | |
| #1023 nodejs plugin: fix the plugin’s dependency installation | snapcraft | merged | Merged into master, this one-line change fixes the nodejs plugin dependency installation, resolving LP #1652542. The commit integrates cleanly with no impact on overall code coverage. | |
| #490 nodejs plugin: Allow building N times | snapcraft | merged | Merged nodejs plugin changes to allow multiple builds by preserving npm downloads instead of deleting them. Approved by @kyrofa and merged after retest requests, resolving LP #1575882. | |
| #936 nodejs plugin: install during pull to support npm run | snapcraft | merged | Merged a nodejs plugin update that installs dependencies during pull operations. This resolves npm run command failures by ensuring required packages are available. Approved by one reviewer and modified five files. | |
| #1633298 nodejs plugin never runs install during pull | snapcraft (launchpad) | closed | Fixed the nodejs plugin to run npm install during the pull phase by correcting the builddir path check, resolving downstream build failures. |