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):
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
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:
Navigate to the custom node folder via command line:
cd C:\Users\Gebruiker\AppData\Roaming\npm\node_modules\node-red-contrib-ui-svg
Build a package from within the custom node folder:
npm-pack-all
A few seconds later the tgz archive file will be created:
This tgz file contains a tar file, which in turn contains a directory with ALL the dependent packages:
Now uninstall the global custom node package again, to avoid conflicts/headache afterwards:
npm uninstall -g node-red-contrib-ui-svg
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:
If everything goes well, the custom node should become available in the palette to use it in your flows:
Hopefully this can help other people with offline installations.
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...
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.
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 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.