I am attempting to package an application which has sqlite3@5.0.0 as a dependency. When running snapcraft I always get a failure during the install phase.
+ npm install -g --prefix /root/parts/cli-worm/install cli-worm-0.2.0.tgz
npm WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/root/parts/cli-worm/install/bin/cli-worm -> /root/parts/cli-worm/install/lib/node_modules/cli-worm/index.js
> sqlite3@5.0.0 install /root/parts/cli-worm/install/lib/node_modules/cli-worm/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
sh: 1: node-pre-gyp: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! sqlite3@5.0.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the sqlite3@5.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-28T20_51_35_266Z-debug.log
Failed to build 'cli-worm'.
I do not have any issues building this package outside of snapcraft, but I have found some blog posts where others have seen this same error. The suggested work around for folks who are seeing this is often to:
npm config set user 0
npm config set unsafe-perm true
https://github.com/mapbox/node-sqlite3/issues/972#issuecomment-531482332
Indeed if I run with the --debug flag, then once I get the failure I can use the cli to set the node paths up, run the npm config commands above and I am able to build the project inside the lxde container.
What I don’t understand is how, within the context of the npm plugin to make it such that the build is ran with these config values set. I can override the build step, but the plugin doesn’t download node until during the build stage; so, at that point there is no npm to configure. I have tried overriding the build and doing
env npm_config_user=0
env npm_config_unsafe_perm=true
snapcraftctl build
That also has no effect.
Here is my current yaml
name: cli-worm
base: core20
version: '0.2.0'
summary: an epub reader for the command line
description: |
A simple command line ncurses style interface for reading epubs
grade: stable
confinement: strict
apps:
cli-worm:
command: env LC_ALL=C.UTF-8 cli-worm # set LC_ALL env value when running to properly display utf8 characters
plugs:
- home
- removable-media
parts:
cli-worm:
source: .
plugin: npm
npm-node-version: 14.15.1
override-build: |
echo 'build start'
pwd
echo 'npm_config_unsafe_perm=true' >> ~/.npmrc
echo 'npm_config_user=0' >> ~/.npmrc
env npm_config_user=0
env npm_config_unsafe_perm=true
snapcraftctl build
stage-packages:
- w3m # used to render xhtml to cli safe text
- gcc # trying to make sqllite compile correction on npm install
- g++ # trying make sqllite compile correction on npm install
- libsqlite3-0
and package.json
{
"name": "cli-worm",
"version": "0.2.0",
"description": "an epub reader for the command line",
"main": "index.js",
"bin": {
"cli-worm": "./index.js"
},
"repository": "chriswininger/cli-worm",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"epub",
"e-reader",
"ebooks",
"cli",
"worm",
"cli-worm"
],
"author": "Chris Wininger",
"license": "MIT",
"dependencies": {
"async": "^3.1.1",
"blessed": "^0.1.81",
"dotenv": "^5.0.0",
"log4js": "^3.0.6",
"mkdirp": "^1.0.4",
"sqlite": "^4.0.17",
"sqlite3": "5.0.0",
"tmp": "0.0.33",
"yauzl": "2.10.0",
"xml-parser": "^1.2.1"
}
}
What are my options here? Is there a way to control what flags the npm plugin uses when executing npm install? Why do I need these to to run npm install within the context of the snapcraft build process in the first place?
Any help would be much appreciated.