I decided to try and searched node-red setting.js to add moment:require('moment')
the npm install moment (on the same dir)
after that npm says
found 6 vulnerabilities (2 low, 2 moderate, 2 high) in 338 scanned packages
run `npm audit fix` to fix 4 of them.
1 vulnerability requires semver-major dependency updates.
1 vulnerability requires manual review. See the full report for details.
like and idiot i run npm audit fix on the same dir and I made the omelet
now node-red doesn't start and if I try manually to start says:
Starting as a systemd service.
/usr/lib/node_modules/node-red/red.js:326
}).otherwise(function(err) {
^
TypeError: undefined is not a function
at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:326:4)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 61.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
/usr/lib/node_modules/node-red/red.js:326
}).otherwise(function(err) {
^
TypeError: undefined is not a function
at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:326:4)
at Module._compile (internal/modules/cjs/loader.js:1158:30).......
recursively.
I don't know what can I do to restore.
Someone can help me please???
Well make a backup of the flows file immediately, the errors are nothing to do with your actual flow, but are due to installed node issues. Back up everything in the .node-red directory except node_modules.
I suggest you start by removing the node_modules folder and also remove package-lock.json (not package.json). Then go into your .node-red folder and run npm install
That will reinstall all the nodes back to the version in package.json (it may take a while on a low power machine). If you still have problems then post package.json here and tell us what the problem is. Also tell us what hardware/OS you are running on and in a terminal run node-red
and post the full output here.
You didn't make that clear, in that case it is node red itself you have messed up, so my suggestions will not help.
Instead run the node red install/upgrade script from the node red docs for installing on the pi, that should reinstall node red and probably fix it.
I made it and (two times, one as pi user one as root) and it resolve many modules but not all, get some error because some modules is not updated and not compatible with new node-red (serialport i.e.)
and this is result...
MySQLdatabase
ui_tab
ui_base
ncd-comm
ui_group
ui_spacer
ui_template
camerapi-takephoto
ui_gauge
ui_text
ui_text_input
ui_dropdown
mysql
moment
ui_date_picker
ui_button
join-wait
ncd-ads1115
base64
ui_led
ui_switch
ui_chart
ui_text-input
ui_ui_control
InvertUltimate
BooleanLogicUltimate```
now I try manually or you suggest me to try " npm install" on /usr/lib/node_module/node-red ?
The only thing you should do as root is to install global modules (using npm install -g) which there is generally no need to do.
What did you do as root?
Absolutely not. In your .node-red folder (usually /home/pi/.node-red) which is where the flows file is. Where did you get the idea that you should do anything in /usr/lib? Don't.
You are not the first to be messed up by running npm audit. Those messages are not something the node-red team has any control over.
Having used sudo with npm for local nodes you may find you have files under your home directory owned by root which may cause you problems installing or removing nodes in the future. If you do then you need to set all files in your home directory back to being owned by the node-red user (probably pi).
yes, some modules had root:root as owner:group, I change this like the others pi:pi but....
dashboard doesn't work, when I open localhost:1880/ui it open screen with this like the first time
Welcome to the Node-RED Dashboard
Please add some UI nodes to your flow and redeploy.
I think when (out of ignorance) I ran "npm audit fix" under "/usr/lib/node_module/node-red" I shit and now, I can see the flow, I have all nodes configured as before, tab and group of the dashboards are in place but the dashboard does not start.
inside the dir "/usr/lib/node_module" the dir "node-red" has disappeared
moreover, before to enter node-red and the dashboard I used the username and password that I had set in the node-red configuration, now there is no longer the request.
problem of dashboard was that I had ncd-comm module not installed but a configuration in a flow that used it and deploy stop before to start.
I deleted this and now I'm really working.
NEVER run npm audit fix unless you REALLY know what you are doing. It will nearly always break something.
If you get totally in a mess with installed modules, don't forget that you can always delete the node_modules folder as long as you have a matching package.json file that contains the module details. Then you can simply do an npm install and everything will be restored.
A bonus 3rd learning point is that it is highly recommended that you learn the basics of npm and the file/folder structures it produces. It doesn't take much and it will really help you out in the future.