Node-RED goes into error following a restart. (Using pm2)

Hi all, I had a functioning Node-RED app running on a linux server. I was working on another app on the same server that required the installation of "node-fetch". Following the installation of "node-fetch", I restarted node-RED and now it goes into errored status 1-2sec after starting.

Following the issue I tried uninstalling node-fetch to at least get access back to the initial application but node-red still seems to refer to node-fetch being in error.

Here are the error logs:


/home/nred/.pm2/pm2.log last 15 lines:
PM2 | 2023-08-22T15:59:12: PM2 log: App [node-red:2] online
PM2 | 2023-08-22T15:59:12: PM2 log: App [node-red:2] exited with code [0] via signal [SIGINT]
PM2 | 2023-08-22T15:59:12: PM2 log: App [node-red:2] starting in -fork mode-
PM2 | 2023-08-22T15:59:12: PM2 log: App [node-red:2] online
PM2 | 2023-08-22T15:59:13: PM2 log: App [node-red:2] exited with code [0] via signal [SIGINT]
PM2 | 2023-08-22T15:59:13: PM2 log: App [node-red:2] starting in -fork mode-
PM2 | 2023-08-22T15:59:13: PM2 log: App [node-red:2] online
PM2 | 2023-08-22T15:59:14: PM2 log: App [node-red:2] exited with code [0] via signal [SIGINT]
PM2 | 2023-08-22T15:59:14: PM2 log: App [node-red:2] starting in -fork mode-
PM2 | 2023-08-22T15:59:14: PM2 log: App [node-red:2] online
PM2 | 2023-08-22T15:59:15: PM2 log: App [node-red:2] exited with code [0] via signal [SIGINT]
PM2 | 2023-08-22T15:59:15: PM2 log: App [node-red:2] starting in -fork mode-
PM2 | 2023-08-22T15:59:15: PM2 log: App [node-red:2] online
PM2 | 2023-08-22T15:59:15: PM2 log: App [node-red:2] exited with code [0] via signal [SIGINT]
PM2 | 2023-08-22T15:59:15: PM2 log: Script /home/nred/.nvm/versions/node/v16.16.0/bin/node-red had too many unstable restarts (16). Stopped. "errored"



2|node-red |     at Script.runInContext (node:vm:139:12)
2|node-red |     at processMessage (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:401:33)
2|node-red |     at FunctionNode._inputCallback (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:335:17)
2|node-red |     at /home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
2|node-red | TypeError: Only absolute URLs are supported
2|node-red |     at getNodeRequestOptions (/home/nred/.node-red/node_modules/node-fetch/lib/index.js:1327:9)
2|node-red |     at /home/nred/.node-red/node_modules/node-fetch/lib/index.js:1440:19
2|node-red |     at new Promise (<anonymous>)
2|node-red |     at new fetch (/home/nred/.node-red/node_modules/node-fetch/lib/index.js:1437:9)
2|node-red |     at Function node:13c3ef142b1f92f1 [function 2]:3:15
2|node-red |     at Function node:13c3ef142b1f92f1 [function 2]:19:3
2|node-red |     at Script.runInContext (node:vm:139:12)
2|node-red |     at processMessage (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:401:33)
2|node-red |     at FunctionNode._inputCallback (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:335:17)
2|node-red |     at /home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:210:26
2|node-red | /home/nred/.node-red/settings.js:48
2|node-red |     flowFilePretty: true,
2|node-red |                   ^
2|node-red |
2|node-red | SyntaxError: Unexpected token ':'
2|node-red |     at Object.compileFunction (node:vm:352:18)
2|node-red |     at wrapSafe (node:internal/modules/cjs/loader:1033:15)
2|node-red |     at Module._compile (node:internal/modules/cjs/loader:1069:27)
2|node-red |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2|node-red |     at Module.load (node:internal/modules/cjs/loader:981:32)
2|node-red |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2|node-red |     at Module.require (node:internal/modules/cjs/loader:1005:19)
2|node-red |     at Module.Hook._require.Module.require (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
2|node-red |     at require (node:internal/modules/cjs/helpers:102:18)
2|node-red |     at Object.<anonymous> (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/red.js:140:20)

I am not sure if the issue is with pm2 or node-red but please help if you have any idea how to solve this issue.

Thank you

Start node-red with --safe

node-red --safe

Then get rid of node-fetch function node, then deploy.

Once running, you can start with pm2 again.

PS, use the built in HTTP request node instead of importing node-fetch.

1 Like

When i do: node-red --safe

I get the following:

Error loading settings file: /home/nred/.node-red/settings.js
/home/nred/.node-red/settings.js:48
flowFilePretty: true,
^

SyntaxError: Unexpected token ':'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (/home/nred/.nvm/versions/node/v16.16.0/lib/node_modules/node-red/red.js:140:20)
at Module._compile (node:internal/modules/cjs/loader:1105:14)

I am looking into the settings.js file to see if I can find something wrong.

EDIT: My settings,js had a typo somewhere. I fixed it and was able to start in safe mode and remove the faulty function.

Thank you!!

Check around that line in your settings.js as you have an error in the syntax. Something like VScode as an editor can really help to find errors or there are online code checkers you can use.

ignore!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.