TypeError: node.type.padEnd is not a function

Hi,

At some point I started getting these error messages in my logs:

May 20 08:43:22 broker1 nodered[13637]: TypeError: node.type.padEnd is not a function
May 20 08:43:22 broker1 nodered[13637]:     at Flow.start (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js:221:62)
May 20 08:43:22 broker1 nodered[13637]:     at start (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/flows/index.js:329:33)
May 20 08:43:22 broker1 nodered[13637]:     at tryCatchReject (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:845:30)
May 20 08:43:22 broker1 nodered[13637]:     at runContinuation1 (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:804:4)
May 20 08:43:22 broker1 nodered[13637]:     at Fulfilled.when (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:592:4)
May 20 08:43:22 broker1 nodered[13637]:     at Pending.run (/usr/lib/node_modules/node-red/node_modules/when/lib/makePromise.js:483:13)
May 20 08:43:22 broker1 nodered[13637]:     at Scheduler._drain (/usr/lib/node_modules/node-red/node_modules/when/lib/Scheduler.js:62:19)
May 20 08:43:22 broker1 nodered[13637]:     at Scheduler.drain (/usr/lib/node_modules/node-red/node_modules/when/lib/Scheduler.js:27:9)
May 20 08:43:22 broker1 nodered[13637]:     at _combinedTickCallback (internal/process/next_tick.js:132:7)
May 20 08:43:22 broker1 nodered[13637]:     at process._tickCallback (internal/process/next_tick.js:181:9)

I'm looking for suggestions at tracking down where the call originate (in order to, well, try fixing it).

Node-RED startup:

May 20 08:43:15 broker1 nodered[13637]: Welcome to Node-RED
May 20 08:43:15 broker1 nodered[13637]: ===================
May 20 08:43:15 broker1 nodered[13637]: 20 May 08:43:15 - [info] Node-RED version: v0.20.5
May 20 08:43:15 broker1 nodered[13637]: 20 May 08:43:15 - [info] Node.js  version: v8.16.0
May 20 08:43:15 broker1 nodered[13637]: 20 May 08:43:15 - [info] Linux 4.14.107-157 arm LE
May 20 08:43:15 broker1 nodered[13637]: 20 May 08:43:15 - [info] Loading palette nodes
May 20 08:43:19 broker1 nodered[13637]: 20 May 08:43:19 - [info] Dashboard version 2.15.1 started at /ui
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [info] Settings file  : /home/nodered/.node-red/settings.js
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [info] Context store  : 'default' [module=memory]
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [info] User directory : /home/nodered/.node-red
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [info] Flows file     : /home/nodered/.node-red/flows.json
May 20 08:43:21 broker1 nodered[13637]: 20 May 08:43:21 - [info] Server now running at https://127.0.0.1:1880/

I did this search in my .node-red directory:

nodered@broker1:~/.node-red$ grep -R padEnd *
node_modules/lodash/string.js:  'padEnd': require('./padEnd'),
node_modules/lodash/core.js:   * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
node_modules/lodash/lodash.min.js:return""},An.stubTrue=function(){return true},An.multiply=tc,An.nth=function(n,t){return n&&n.length?Qt(n,Au(t)):T},An.noConflict=function(){return $n._===this&&($n._=li),this},An.noop=Nu,An.now=Ko,An.pad=function(n,t,r){n=Ou(n);var e=(t=Au(t))?D(n):0;return!t||e>=t?n:(t=(t-e)/2,ne(Oi(t),r)+n+ne(Si(t),r))},An.padEnd=function(n,t,r){n=Ou(n);var e=(t=Au(t))?D(n):0;return t&&e<t?n+ne(t-e,r):n},An.padStart=function(n,t,r){n=Ou(n);var e=(t=Au(t))?D(n):0;return t&&e<t?ne(t-e,r)+n:n},An.parseInt=function(n,t,r){
node_modules/lodash/wrapperLodash.js: * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
node_modules/lodash/lodash.js:     * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
node_modules/lodash/lodash.js:     * _.padEnd('abc', 6);
node_modules/lodash/lodash.js:     * _.padEnd('abc', 6, '_-');
node_modules/lodash/lodash.js:     * _.padEnd('abc', 3);
node_modules/lodash/lodash.js:    function padEnd(string, length, chars) {
node_modules/lodash/lodash.js:    lodash.padEnd = padEnd;
node_modules/lodash/fp/padCharsEnd.js:    func = convert('padCharsEnd', require('../padEnd'));
node_modules/lodash/fp/_mapping.js:    'omitBy', 'overArgs', 'pad', 'padEnd', 'padStart', 'parseInt', 'partial',
node_modules/lodash/fp/_mapping.js:  'padCharsEnd': 'padEnd',
node_modules/lodash/fp/padEnd.js:    func = convert('padEnd', require('../padEnd'));
node_modules/lodash/padEnd.js: * _.padEnd('abc', 6);
node_modules/lodash/padEnd.js: * _.padEnd('abc', 6, '_-');
node_modules/lodash/padEnd.js: * _.padEnd('abc', 3);
node_modules/lodash/padEnd.js:function padEnd(string, length, chars) {
node_modules/lodash/padEnd.js:module.exports = padEnd;

That all looks like defintions of the padEnd function, no actual use of it ...

/michael

Hi @mikejac

You don't need to go searching for calls to padEnd as the stack trace shows you exactly where the call is:

TypeError: node.type.padEnd is not a function
     at Flow.start (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js:221:62) 

This is in the core of Node-RED. It is a very odd error to hit; node.type is always a String, so .padEnd must be defined. The question is how can node.type not be a string.

What 3rd party nodes have you installed?

Hi @knolleary,

This is my package.json file:

nodered@broker1:~/.node-red$ cat package.json
{
  "name": "node-red-project",
  "description": "A Node-RED Project",
  "version": "0.0.1",
  "dependencies": {
    "helmet": "^3.18.0",
    "node-red-contrib-bigtimer": "^2.1.9",
    "node-red-contrib-cast": "^0.2.6",
    "node-red-contrib-google-action": "~1.2.1",
    "node-red-contrib-google-smarthome": "0.0.11",
    "node-red-contrib-homekit-mqtt": "0.0.6",
    "node-red-contrib-jointspace": "0.0.5",
    "node-red-contrib-logic": "0.0.4",
    "node-red-contrib-mos": "^0.1.0",
    "node-red-contrib-node-hue": "^0.9.5",
    "node-red-contrib-sonos-say": "0.0.4",
    "node-red-contrib-unifi": "0.0.6",
    "node-red-contrib-util": "0.0.2",
    "node-red-contrib-zigbee": "^0.7.2",
    "node-red-dashboard": "^2.15.2",
    "node-red-node-base64": "^0.1.3",
    "node-red-node-google": "^0.1.4",
    "node-red-node-msgpack": "^1.1.3",
    "node-red-node-ping": "0.0.16",
    "node-red-node-pushover": "0.0.14",
    "node-red-node-random": "^0.1.2",
    "node-red-node-suncalc": "0.0.11"
  }
}
  1. Some of those nodes are my own.
  2. Is package.json a full list of installed nodes?

/michael

So, helmet doesn't belong here, uninstalled it.

Modified /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js near line 221 to print node data if typeof node.type.padEnd !== 'function'. That reveals this:

[cut]
id: '9b075ae3.4df678',
type: 1,
[cut]

However, flows.json has this data in it:

  {
    "id": "9b075ae3.4df678",
    "type": "homekit-lightbulb-v2",
    "z": "e7bc5d8c.407f68",
    "client": "81d83af1.83d0b",
    "nodename": "dummy",
    "dataid": "LB01",
    "wdt": "-1",
    "accessory": "e70dabd0.5415",
    "name": "Carport, Lys Automatik",
    "serviceName": "Lightbulb",
    "brightness": -1,
    "hue": -1,
    "saturation": -1,
    "x": 470,
    "y": 1300,
    "wires": [
      [
        "a8c19030.946ce8"
      ],
      [
        
      ],
      [
        
      ]
    ]
  }

To me that looks fine (i.e type is a string).

Deleted this node, but then another node got the type: 1 instead :frowning:

Think I'll do a clean install of Node-RED and then restore my config to see what happens ...

Whattayouknow, in some of my (homemade) nodes I have lines like this:

var TYPE = {
        ON:         1,
        BRIGHTNESS: 2,
        ALL:        3
}

var node = this
node.type  = TYPE.ALL

That probably explains it :slight_smile: (but why does this show up now - these nodes has been installed/active for several years by now. Oh well.)

/michael

yup, the node.type assignment in my node was the reason. So fixed now :slight_smile:

1 Like