NPM package build script wants to download a file

I’m trying to build signal-desktop natively, and am familiar with flatpak-node-generator. While I succeeded in getting all the npm packages cached locally with generated-sources.json, one of the packages runs a build script that looks to download something from the Internet:

npm error code 1                                                                                      
npm error path /run/build/signal-desktop/node_modules/@signalapp/better-sqlite3                       
npm error command failed                                                                              
npm error command sh -c npm run download && npm run build-release                                                                                                                              
npm error > @signalapp/better-sqlite3@8.8.1 download                    
npm error > node ./deps/download.js                                                            
npm error                                      
npm error downloading https://build-artifacts.signal.org/desktop/sqlcipher-4.6.1--3.0.7--0.2.1-7c30de8bcb5d21127803f5ab19a097e1b508d05744aca3ac6166352506b5f451.tar.gz
npm error node:events:497                      
npm error       throw er; // Unhandled 'error' event                                                                                                                                           
npm error       ^                              
npm error                                      
npm error Error: getaddrinfo EAI_AGAIN build-artifacts.signal.org                                                                                                                              
npm error     at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26)                                                                                                              
npm error Emitted 'error' event on ClientRequest instance at:                                                                                                                                  
npm error     at emitErrorEvent (node:_http_client:101:11)                                                                                                                                     
npm error     at TLSSocket.socketErrorListener (node:_http_client:504:5)                                                                                                                       
npm error     at TLSSocket.emit (node:events:519:28)                                                                                                                                           
npm error     at emitErrorNT (node:internal/streams/destroy:169:8)                                                                                                                             
npm error     at emitErrorCloseNT (node:internal/streams/destroy:128:3)                                                                                                                        
npm error     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {                                                                                                 
npm error   errno: -3001,                      
npm error   code: 'EAI_AGAIN',                                                                 
npm error   syscall: 'getaddrinfo',                                                            
npm error   hostname: 'build-artifacts.signal.org'                                             
npm error }                                    
npm error                                      
npm error Node.js v20.18.0                                                                     
npm error A complete log of this run can be found in: /run/build/signal-desktop/flatpak-node/npm-cache/_logs/2024-10-16T16_39_38_368Z-debug-0.log
Error: module signal-desktop: Child process exited with code 1

How could I work around this?

If you’re just building locally then you can add --share=network to build-args (see the documentation) to allow network access. This is forbidden on Flathub but can be used for your local builds.

For an offline build there’s probably no other way but to download the needed files manually (i.e. put everything that’s needed as sources into the manifest).

You’ll have to check whether the build system can already use local files (& where to put them) or else you’d have to patch some build scripts.

Thanks - I’ll test with this addition.

Since the goal is to eventually get it to flathub, so --share=network is a temporary fix at best. The problem I see is that whenever npm install is run from the flatpak manifest, node_modules is seemingly mounted as a temporary directory and deleted after the command exits. There seems to be no way to add the required files to the proper nested directory in node_modules since it’s deleted.

Is there a way around that?

As far as I know there is no special handling for node modules: Flatpak just downloads the files from the generated sources & puts them into the destination folder you configure. It should be available for as long as the module is building.

You can also prepare the sources manually with commands before npm install (e.g. mkdir -p, mv or cp).

But you’ll have to share your manifest to identify the issue you’re having.