Steps to create a custom node package for offline installation

Hi folks,

I am absolutely not an NPM expert, so I had some trouble to help @bogi in another discussion. He needed to have a package of my custom node to install it in an offline Node-RED system. Don't know if my way of working is complete or solid, but it seemed to work for me. So sharing the steps I have executed to create such an offline package (containing all dependencies):

  1. Since npm pack doesn't seem to include the node dependencies inside the package, I installed the npm-pack-all package globally:

    npm install npm-pack-all
    
  2. Then I had to install my custom node globally (-g):

    npm install node-red-contrib-ui-svg
    

    Note that it seems only to work when you install it globally, since only then the dependencies are being installed in the nested node_modules folder:

    image

  3. Navigate to the custom node folder via command line:

    cd C:\Users\Gebruiker\AppData\Roaming\npm\node_modules\node-red-contrib-ui-svg
    
  4. Build a package from within the custom node folder:

    npm-pack-all
    
  5. A few seconds later the tgz archive file will be created:

    image

    This tgz file contains a tar file, which in turn contains a directory with ALL the dependent packages:

    image

  6. Now uninstall the global custom node package again, to avoid conflicts/headache afterwards:

    npm uninstall -g node-red-contrib-ui-svg
    
  7. Test the package, by opening the "Manage palette" of your Node-RED (which doesn't hav the custom node installed yet!), and navigate to the tgz file and upload it:

    image

  8. If everything goes well, the custom node should become available in the palette to use it in your flows:

    image

Hopefully this can help other people with offline installations.

Bart

2 Likes

Hi Bart - as I replied in another thread - you can use the normal npm pack as long as you add the dependencies to a bundleddependencies section of your package.json - and run npm i locally before running npm pack (which usually I have done while developing a node anyway) . Not ideal if this means you end up creating two versions of your node (one with and one without dependencies) - and of course it doesn't then let npm try to optimise the installed libraries to reduce size - but for offline work it does work.

Hi Dave,
Thanks for sharing that alternative!
I had also seen that `bundleddependencies´ tonight, but I wasn't sure whether that also works for nested dependencies? Suppose my node depends - via bundleddependencies - on package A, but package A depends in turn on another package B. Does this mean that package A also needs to use bundleddependencies for package B? I assume not, because then it would become hopeless to manage the entire dependency tree...

Ah ok, I see now that Bogi also mentioned that same tgz file in that other discussion...

It seems to work for me if I specify the top level other libraries I need. (And run npm install) so they are all loaded locally. That seems to then pack up the sub-dependencies also.

1 Like

Hy BartButenaers, thanks for this info it helped me alot, i am also new to NODE-RED and NPM. By following the process you have mentioned I am able to upload few modules using tgz file. But i am facing issue with some modules.

I am facing issue in installing these nodes GitHub - okhiroyuki/red-mobile-nodes: Extra nodes for RedMobile using a tgz file file. Could you please help me with it. I am also facing issue in generating a module using NPM run build as mentioned in this tutorial : GitHub - okhiroyuki/redmobile-modules-generator: Node Modules generator for customizing RedMobile's Node-RED

The name of the package is @red-mobile/red-mobile-nodes not red-mobile-nodes

See here: @red-mobile/red-mobile-nodes - npm

2 Likes

Thanks it worked, Could you please see the issue in this tutorial of Node-red module generator: GitHub - okhiroyuki/redmobile-modules-generator: Node Modules generator for customizing RedMobile's Node-RED
npm run build doesn't work and publish following error

you are in the wrong directory.

go back up to the redmobile folder and try again

I suspect you need to be 2 directories further up (in where the package.json exists)

Other than that, you will have to ask on the repositories "issues" page.

i have tried following the same process in all the directories where i have cloned redmobile-modules-generator. But its not working all have some issue.